mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-20 17:50:16 -04:00
feat(destinations): add search to college and student list views
This commit is contained in:
parent
74b6932c75
commit
5d4e9a1516
|
@ -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,8 +59,20 @@ class CollegeDestinationListView(
|
|||
): # pylint: disable=too-many-ancestors
|
||||
model = College
|
||||
paginate_by = 20
|
||||
|
||||
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 = (
|
||||
College.objects.annotate(
|
||||
queryset.annotate( # type: ignore # mypy is annoying
|
||||
count_decisions=Count(
|
||||
"decision", filter=Q(decision__user__publish_data=True)
|
||||
),
|
||||
|
@ -113,6 +137,19 @@ class CollegeDestinationListView(
|
|||
.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
|
||||
|
||||
|
|
|
@ -7,11 +7,31 @@
|
|||
|
||||
<p><b>Note</b>: All data is self-reported. We do not make any claim as to the accuracy of this data.</p>
|
||||
|
||||
{% if search_query %}
|
||||
<p>
|
||||
Only showing colleges matching {{ search_query }}.
|
||||
Navigate <a href="{% url "destinations:colleges" %}">here</a> to reset.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<div class="container pb-3">
|
||||
<form method="get">
|
||||
<div class="form-floating mb-3">
|
||||
<div class="input-group">
|
||||
<div class="input-group-text"><i class="fas fa-search"></i></div>
|
||||
<input type="search" name="q" id="search" data-toggle="tooltip" data-bs-placement="bottom"
|
||||
title="Filter by college name, CEEB code, city, or state abbreviation" aria-label="Search"
|
||||
class="form-control" value="{{ search_query }}">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">University Name</th>
|
||||
<th scope="col">University Name, Location, CEEB code</th>
|
||||
<th scope="col">Total Applications</th>
|
||||
<th scope="col">Admitted</th>
|
||||
<th scope="col">Waitlisted</th>
|
||||
|
@ -26,7 +46,7 @@
|
|||
<tbody>
|
||||
{% for college in object_list %}
|
||||
<tr>
|
||||
<th scope="row"><a href="{% url "destinations:students" %}?college={{ college.id }}">{{ college.name }}</a></th>
|
||||
<th scope="row"><a href="{% url "destinations:students" %}?college={{ college.id }}">{{ college }}</a></th>
|
||||
<td>{{ college.count_decisions }}</td>
|
||||
<td>{{ college.count_admit }}</td>
|
||||
<td>{{ college.count_waitlist }}</td>
|
||||
|
|
|
@ -7,10 +7,26 @@
|
|||
|
||||
<p><b>Note</b>: All data is self-reported. We do not make any claim as to the accuracy of this data.</p>
|
||||
|
||||
{% if college %}
|
||||
<p>Only showing students reporting applications to {{ college }}.</p>
|
||||
{% if college or search_query %}
|
||||
<p>
|
||||
Only showing students {% if college %}reporting applications to {{ college }}
|
||||
{% if search_query %}and {% endif %}{% endif %}{% if search_query %}matching {{ search_query }}{% endif %}.
|
||||
Navigate <a href="{% url "destinations:students" %}">here</a> to reset.
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
<div class="container pb-3">
|
||||
<form method="get">
|
||||
<div class="form-floating mb-3">
|
||||
<div class="input-group">
|
||||
<div class="input-group-text"><i class="fas fa-search"></i></div>
|
||||
{% if college %}<input type="hidden" name="college" value="{{ college.id }}">{% endif %}
|
||||
<input type="search" name="q" id="search" data-toggle="tooltip" data-bs-placement="bottom" title="Filter by first name, last name, and biography" aria-label="Search" class="form-control" value="{{ search_query }}">
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<thead>
|
||||
|
@ -49,7 +65,7 @@
|
|||
</tbody>
|
||||
</table>
|
||||
</td>
|
||||
<td class="text-wrap text-break" style="max-width: 400px;">{{ senior.biography|linebreaks }}</td>
|
||||
<td class="text-wrap text-break" style="max-width: 400px;">{{ senior.biography|linebreaks|striptags }}</td>
|
||||
<td>
|
||||
{# Decisions #}
|
||||
<table class="table table-sm">
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<p>You are about to delete this decision:</p>
|
||||
|
||||
<p>{{ object.college.name }} {{ object.get_decision_type_display }}</p>
|
||||
<p>{{ object }}</p>
|
||||
|
||||
<input type="submit" value="Confirm" class="btn btn-danger">
|
||||
</form>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<p>You are about to delete this test score:</p>
|
||||
|
||||
<p>{{ object.get_exam_type_display }}: {{ object.exam_score }}</p>
|
||||
<p>{{ object }}</p>
|
||||
|
||||
<input type="submit" value="Confirm" class="btn btn-danger">
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue
Block a user