This repository has been archived on 2023-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
python-blog/articles/context_processors.py

49 lines
1.2 KiB
Python
Raw Normal View History

2020-09-12 17:02:29 +02:00
from django.conf import settings
2020-08-17 09:57:24 +02:00
from articles.models import Article, Page
2020-11-28 20:09:37 +01:00
from attachments.models import Attachment
2020-08-17 09:57:24 +02:00
2020-09-05 09:04:45 +02:00
IGNORED_PATHS = [
"/robots.txt",
]
2020-08-17 09:57:24 +02:00
def pages(request):
2020-09-05 09:04:45 +02:00
if request.path in IGNORED_PATHS:
return {}
return {"pages": Page.objects.filter(status=Article.PUBLISHED).exclude(position=0)}
2020-08-18 14:23:51 +02:00
def drafts_count(request):
2020-09-05 09:04:45 +02:00
if request.path in IGNORED_PATHS:
return {}
return {"drafts_count": Article.objects.filter(status=Article.DRAFT).count()}
def date_format(request):
2020-09-05 09:04:45 +02:00
if request.path in IGNORED_PATHS:
return {}
2020-08-25 23:15:08 +02:00
return {"CUSTOM_ISO": r"Y-m-d\TH:i:sO"}
2020-09-09 18:32:46 +02:00
def git_version(request):
if request.path in IGNORED_PATHS:
return {}
try:
with open("/app/.version") as f:
2020-09-12 17:02:29 +02:00
version = f.read().strip()
url = settings.BLOG["repo"]["commit_url"].format(commit_sha=version)
version = version[:8]
2020-09-09 18:32:46 +02:00
except FileNotFoundError:
version = "latest"
2020-09-12 17:02:29 +02:00
url = settings.BLOG["repo"]["log"]
return {"git_version": version, "git_version_url": url}
def plausible(request):
return {"plausible_domain": settings.PLAUSIBLE_DOMAIN}
2020-11-28 20:09:37 +01:00
def open_graph_image(request):
return {"open_graph_image": Attachment.objects.get_open_graph_image()}