diff --git a/web/core/context_processors.py b/web/core/context_processors.py index 8060316..5e3f4ad 100644 --- a/web/core/context_processors.py +++ b/web/core/context_processors.py @@ -1,4 +1,5 @@ from pathlib import Path +from .models_ann import Announcement, AnnouncementDismissal def app_version(request): version_file = Path(__file__).resolve().parent.parent / "version.txt" @@ -7,4 +8,21 @@ def app_version(request): version = f.read().strip() except FileNotFoundError: version = "v0.0.0" - return {"APP_VERSION": version} \ No newline at end of file + 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} \ No newline at end of file