diff --git a/intranet/apps/search/views.py b/intranet/apps/search/views.py index 3c0468d48c8..66b5df3f209 100644 --- a/intranet/apps/search/views.py +++ b/intranet/apps/search/views.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import logging from django.conf import settings @@ -7,7 +9,7 @@ from django.shortcuts import redirect, render from ...utils.helpers import is_entirely_digit -from ..announcements.models import AnnouncementManager +from ..announcements.models import Announcement, AnnouncementManager from ..auth.decorators import deny_restricted from ..eighth.models import EighthActivity from ..enrichment.models import EnrichmentActivity @@ -214,14 +216,24 @@ def do_courses_search(q): return Course.objects.filter(filter_query).order_by("name") -def do_announcements_search(q, user): +def do_announcements_search(q, user) -> tuple[list[Announcement], list[Announcement]]: + """Search for announcements. + + Returns: + A tuple of the announcements and club announcements + """ filter_query = get_query(q, ["title", "content"]) entries = AnnouncementManager().visible_to_user(user).filter(filter_query).order_by("title") - final_entries = [] + club_announcements = [] + announcements = [] for e in entries: - if e.is_this_year: - final_entries.append(e) - return final_entries + if not e.is_this_year: + continue + if e.activity is None: + announcements.append(e) + else: + club_announcements.append(e) + return (announcements, club_announcements) def do_events_search(q): @@ -266,7 +278,7 @@ def search_view(request): users = sorted(users, key=lambda u: (u.last_name, u.first_name)) activities = do_activities_search(q) - announcements = do_announcements_search(q, request.user) + announcements, club_announcements = do_announcements_search(q, request.user) events = do_events_search(q) enrichments = do_enrichment_search(q) if settings.ENABLE_ENRICHMENT_APP else [] classes = do_courses_search(q) @@ -282,6 +294,7 @@ def search_view(request): "search_query": q, "search_results": users, # User objects "announcements": announcements, # Announcement objects + "club_announcements": club_announcements, # Club Announcement objects "events": events, # Event objects "enrichments": enrichments, # EnrichmentActivity objects "activities": activities, # EighthActivity objects diff --git a/intranet/templates/search/search_results.html b/intranet/templates/search/search_results.html index 1da1abef011..e76ae7f7a06 100644 --- a/intranet/templates/search/search_results.html +++ b/intranet/templates/search/search_results.html @@ -140,6 +140,27 @@

Announcements

{% else %} No results. {% endif %} + +

+

Club Announcements

+ {% if club_announcements %} + {{ club_announcements|length }} result{{ club_announcements|pluralize }} + + {% for a in club_announcements %} + + + + {% endfor %} +
+ + {{ a.title|safe }} +
+     {{ a.content|truncatechars_html:"50"|striptags }} +
+ {% else %} + No results. + {% endif %} + {% endif %} {% if search_query and DJANGO_SETTINGS.ENABLE_ENRICHMENT_APP %}