Update web/core/context_processors.py
This commit is contained in:
parent
28009ce6ae
commit
c32c8cb0e6
@ -1,4 +1,5 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from .models_ann import Announcement, AnnouncementDismissal
|
||||||
|
|
||||||
def app_version(request):
|
def app_version(request):
|
||||||
version_file = Path(__file__).resolve().parent.parent / "version.txt"
|
version_file = Path(__file__).resolve().parent.parent / "version.txt"
|
||||||
@ -7,4 +8,21 @@ def app_version(request):
|
|||||||
version = f.read().strip()
|
version = f.read().strip()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
version = "v0.0.0"
|
version = "v0.0.0"
|
||||||
return {"APP_VERSION": version}
|
return {"APP_VERSION": version}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def pending_announcement(request):
|
||||||
|
"""
|
||||||
|
Expose the latest active, current announcement the user has not dismissed.
|
||||||
|
We'll only use it on the Search page via include.
|
||||||
|
"""
|
||||||
|
user = getattr(request, "user", None)
|
||||||
|
if not (user and user.is_authenticated):
|
||||||
|
return {"pending_announcement": None}
|
||||||
|
|
||||||
|
current = [a for a in Announcement.objects.all() if a.is_current()]
|
||||||
|
for a in current:
|
||||||
|
if not AnnouncementDismissal.objects.filter(user=user, announcement=a).exists():
|
||||||
|
return {"pending_announcement": a}
|
||||||
|
return {"pending_announcement": None}
|
||||||
Loading…
Reference in New Issue
Block a user