Skip to content

Commit

Permalink
feat: search for club announcements
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGrace2282 committed Oct 4, 2024
1 parent 8d4abda commit fa826b9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
27 changes: 20 additions & 7 deletions intranet/apps/search/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import logging

from django.conf import settings
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
21 changes: 21 additions & 0 deletions intranet/templates/search/search_results.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,27 @@ <h3>Announcements</h3>
{% else %}
<b>No results.</b>
{% endif %}

<br><br>
<h3>Club Announcements</h3>
{% if club_announcements %}
{{ club_announcements|length }} result{{ club_announcements|pluralize }}
<table class="list-table announcements-table">
{% for a in club_announcements %}
<tr>
<td class="list-item">
<a href="{% url 'view_announcement' a.id %}">
{{ a.title|safe }}
</a><br>
&nbsp; &nbsp; {{ a.content|truncatechars_html:"50"|striptags }}
</td>
</tr>
{% endfor %}
</table>
{% else %}
<b>No results.</b>
{% endif %}

{% endif %}

{% if search_query and DJANGO_SETTINGS.ENABLE_ENRICHMENT_APP %}
Expand Down

0 comments on commit fa826b9

Please sign in to comment.