diff --git a/tjdests/apps/destinations/views.py b/tjdests/apps/destinations/views.py index ead33dc..c49aed3 100644 --- a/tjdests/apps/destinations/views.py +++ b/tjdests/apps/destinations/views.py @@ -1,5 +1,5 @@ from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin -from django.db.models import Count, Q +from django.db.models import Count, Q, QuerySet from django.shortcuts import get_object_or_404 from django.views.generic import ListView @@ -23,6 +23,14 @@ class StudentDestinationListView( get_object_or_404(College, id=college_id) queryset = queryset.filter(decision__college__id=college_id) + search_query = self.request.GET.get("q", None) + if search_query is not None: + queryset = queryset.filter( + Q(first_name__icontains=search_query) + | Q(last_name__icontains=search_query) + | Q(biography__icontains=search_query) + ) + return queryset def get_context_data( @@ -34,6 +42,10 @@ class StudentDestinationListView( if college_id is not None: context["college"] = get_object_or_404(College, id=college_id) + search_query = self.request.GET.get("q", None) + if search_query is not None: + context["search_query"] = search_query + return context def test_func(self): @@ -47,71 +59,96 @@ class CollegeDestinationListView( ): # pylint: disable=too-many-ancestors model = College paginate_by = 20 - queryset = ( - College.objects.annotate( - count_decisions=Count( - "decision", filter=Q(decision__user__publish_data=True) - ), - count_admit=Count( - "decision", - filter=Q( - decision__admission_status=Decision.ADMIT, - decision__user__publish_data=True, + + def get_queryset(self) -> QuerySet: + search_query = self.request.GET.get("q", None) + if search_query is not None: + queryset = College.objects.filter( + Q(name__icontains=search_query) + | Q(location__icontains=search_query) + | Q(ceeb_code__icontains=search_query) + ) + else: + queryset = College.objects.all() + + queryset = ( + queryset.annotate( # type: ignore # mypy is annoying + count_decisions=Count( + "decision", filter=Q(decision__user__publish_data=True) ), - ), - count_waitlist=Count( - "decision", - filter=Q( - decision__admission_status=Decision.WAITLIST, - decision__user__publish_data=True, + count_admit=Count( + "decision", + filter=Q( + decision__admission_status=Decision.ADMIT, + decision__user__publish_data=True, + ), ), - ), - count_waitlist_admit=Count( - "decision", - filter=Q( - decision__admission_status=Decision.WAITLIST_ADMIT, - decision__user__publish_data=True, + count_waitlist=Count( + "decision", + filter=Q( + decision__admission_status=Decision.WAITLIST, + decision__user__publish_data=True, + ), ), - ), - count_waitlist_deny=Count( - "decision", - filter=Q( - decision__admission_status=Decision.WAITLIST_DENY, - decision__user__publish_data=True, + count_waitlist_admit=Count( + "decision", + filter=Q( + decision__admission_status=Decision.WAITLIST_ADMIT, + decision__user__publish_data=True, + ), ), - ), - count_defer=Count( - "decision", - filter=Q( - decision__admission_status=Decision.DEFER, - decision__user__publish_data=True, + count_waitlist_deny=Count( + "decision", + filter=Q( + decision__admission_status=Decision.WAITLIST_DENY, + decision__user__publish_data=True, + ), ), - ), - count_defer_admit=Count( - "decision", - filter=Q( - decision__admission_status=Decision.DEFER_ADMIT, - decision__user__publish_data=True, + count_defer=Count( + "decision", + filter=Q( + decision__admission_status=Decision.DEFER, + decision__user__publish_data=True, + ), ), - ), - count_defer_deny=Count( - "decision", - filter=Q( - decision__admission_status=Decision.DEFER_DENY, - decision__user__publish_data=True, + count_defer_admit=Count( + "decision", + filter=Q( + decision__admission_status=Decision.DEFER_ADMIT, + decision__user__publish_data=True, + ), ), - ), - count_deny=Count( - "decision", - filter=Q( - decision__admission_status=Decision.DENY, - decision__user__publish_data=True, + count_defer_deny=Count( + "decision", + filter=Q( + decision__admission_status=Decision.DEFER_DENY, + decision__user__publish_data=True, + ), ), - ), + count_deny=Count( + "decision", + filter=Q( + decision__admission_status=Decision.DENY, + decision__user__publish_data=True, + ), + ), + ) + .filter(count_decisions__gte=1) + .order_by("name") ) - .filter(count_decisions__gte=1) - .order_by("name") - ) + + return queryset + + def get_context_data( + self, *, object_list=None, **kwargs + ): # pylint: disable=unused-argument + context = super().get_context_data(**kwargs) + + search_query = self.request.GET.get("q", None) + if search_query is not None: + context["search_query"] = search_query + + return context def test_func(self): return self.request.user.accepted_terms diff --git a/tjdests/templates/destinations/college_list.html b/tjdests/templates/destinations/college_list.html index fa50dd8..7c9c919 100644 --- a/tjdests/templates/destinations/college_list.html +++ b/tjdests/templates/destinations/college_list.html @@ -7,11 +7,31 @@

Note: All data is self-reported. We do not make any claim as to the accuracy of this data.

+ {% if search_query %} +

+ Only showing colleges matching {{ search_query }}. + Navigate here to reset. +

+ {% endif %} + +
+
+
+
+
+ +
+
+
+
+
- + @@ -26,7 +46,7 @@ {% for college in object_list %} - + diff --git a/tjdests/templates/destinations/student_list.html b/tjdests/templates/destinations/student_list.html index cfd84b9..ad5da84 100644 --- a/tjdests/templates/destinations/student_list.html +++ b/tjdests/templates/destinations/student_list.html @@ -7,10 +7,26 @@

Note: All data is self-reported. We do not make any claim as to the accuracy of this data.

- {% if college %} -

Only showing students reporting applications to {{ college }}.

+ {% if college or search_query %} +

+ Only showing students {% if college %}reporting applications to {{ college }} + {% if search_query %}and {% endif %}{% endif %}{% if search_query %}matching {{ search_query }}{% endif %}. + Navigate here to reset. +

{% endif %} +
+
+
+
+
+ {% if college %}{% endif %} + +
+
+ +
+
University NameUniversity Name, Location, CEEB code Total Applications Admitted Waitlisted
{{ college.name }}{{ college }} {{ college.count_decisions }} {{ college.count_admit }} {{ college.count_waitlist }}
@@ -49,7 +65,7 @@
- {{ senior.biography|linebreaks }} + {{ senior.biography|linebreaks|striptags }} {# Decisions #} diff --git a/tjdests/templates/profile/decision_delete.html b/tjdests/templates/profile/decision_delete.html index fd0bb62..7fd187a 100644 --- a/tjdests/templates/profile/decision_delete.html +++ b/tjdests/templates/profile/decision_delete.html @@ -11,7 +11,7 @@

You are about to delete this decision:

-

{{ object.college.name }} {{ object.get_decision_type_display }}

+

{{ object }}

diff --git a/tjdests/templates/profile/testscore_delete.html b/tjdests/templates/profile/testscore_delete.html index 123b7e4..58fc4e1 100644 --- a/tjdests/templates/profile/testscore_delete.html +++ b/tjdests/templates/profile/testscore_delete.html @@ -11,7 +11,7 @@

You are about to delete this test score:

-

{{ object.get_exam_type_display }}: {{ object.exam_score }}

+

{{ object }}