28 lines
962 B
Python
28 lines
962 B
Python
from pathlib import Path
|
|
from .models_ann import Announcement, AnnouncementDismissal
|
|
|
|
def app_version(request):
|
|
version_file = Path(__file__).resolve().parent.parent / "version.txt"
|
|
try:
|
|
with open(version_file, "r") as f:
|
|
version = f.read().strip()
|
|
except FileNotFoundError:
|
|
version = "v0.0.0"
|
|
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} |