mirror of
https://github.com/etnguyen03/tjdests.git
synced 2025-04-20 09:40: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.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.shortcuts import get_object_or_404
|
||||||
from django.views.generic import ListView
|
from django.views.generic import ListView
|
||||||
|
|
||||||
|
@ -23,6 +23,14 @@ class StudentDestinationListView(
|
||||||
get_object_or_404(College, id=college_id)
|
get_object_or_404(College, id=college_id)
|
||||||
queryset = queryset.filter(decision__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
|
return queryset
|
||||||
|
|
||||||
def get_context_data(
|
def get_context_data(
|
||||||
|
@ -34,6 +42,10 @@ class StudentDestinationListView(
|
||||||
if college_id is not None:
|
if college_id is not None:
|
||||||
context["college"] = get_object_or_404(College, id=college_id)
|
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
|
return context
|
||||||
|
|
||||||
def test_func(self):
|
def test_func(self):
|
||||||
|
@ -47,71 +59,96 @@ class CollegeDestinationListView(
|
||||||
): # pylint: disable=too-many-ancestors
|
): # pylint: disable=too-many-ancestors
|
||||||
model = College
|
model = College
|
||||||
paginate_by = 20
|
paginate_by = 20
|
||||||
queryset = (
|
|
||||||
College.objects.annotate(
|
def get_queryset(self) -> QuerySet:
|
||||||
count_decisions=Count(
|
search_query = self.request.GET.get("q", None)
|
||||||
"decision", filter=Q(decision__user__publish_data=True)
|
if search_query is not None:
|
||||||
),
|
queryset = College.objects.filter(
|
||||||
count_admit=Count(
|
Q(name__icontains=search_query)
|
||||||
"decision",
|
| Q(location__icontains=search_query)
|
||||||
filter=Q(
|
| Q(ceeb_code__icontains=search_query)
|
||||||
decision__admission_status=Decision.ADMIT,
|
)
|
||||||
decision__user__publish_data=True,
|
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_admit=Count(
|
||||||
count_waitlist=Count(
|
"decision",
|
||||||
"decision",
|
filter=Q(
|
||||||
filter=Q(
|
decision__admission_status=Decision.ADMIT,
|
||||||
decision__admission_status=Decision.WAITLIST,
|
decision__user__publish_data=True,
|
||||||
decision__user__publish_data=True,
|
),
|
||||||
),
|
),
|
||||||
),
|
count_waitlist=Count(
|
||||||
count_waitlist_admit=Count(
|
"decision",
|
||||||
"decision",
|
filter=Q(
|
||||||
filter=Q(
|
decision__admission_status=Decision.WAITLIST,
|
||||||
decision__admission_status=Decision.WAITLIST_ADMIT,
|
decision__user__publish_data=True,
|
||||||
decision__user__publish_data=True,
|
),
|
||||||
),
|
),
|
||||||
),
|
count_waitlist_admit=Count(
|
||||||
count_waitlist_deny=Count(
|
"decision",
|
||||||
"decision",
|
filter=Q(
|
||||||
filter=Q(
|
decision__admission_status=Decision.WAITLIST_ADMIT,
|
||||||
decision__admission_status=Decision.WAITLIST_DENY,
|
decision__user__publish_data=True,
|
||||||
decision__user__publish_data=True,
|
),
|
||||||
),
|
),
|
||||||
),
|
count_waitlist_deny=Count(
|
||||||
count_defer=Count(
|
"decision",
|
||||||
"decision",
|
filter=Q(
|
||||||
filter=Q(
|
decision__admission_status=Decision.WAITLIST_DENY,
|
||||||
decision__admission_status=Decision.DEFER,
|
decision__user__publish_data=True,
|
||||||
decision__user__publish_data=True,
|
),
|
||||||
),
|
),
|
||||||
),
|
count_defer=Count(
|
||||||
count_defer_admit=Count(
|
"decision",
|
||||||
"decision",
|
filter=Q(
|
||||||
filter=Q(
|
decision__admission_status=Decision.DEFER,
|
||||||
decision__admission_status=Decision.DEFER_ADMIT,
|
decision__user__publish_data=True,
|
||||||
decision__user__publish_data=True,
|
),
|
||||||
),
|
),
|
||||||
),
|
count_defer_admit=Count(
|
||||||
count_defer_deny=Count(
|
"decision",
|
||||||
"decision",
|
filter=Q(
|
||||||
filter=Q(
|
decision__admission_status=Decision.DEFER_ADMIT,
|
||||||
decision__admission_status=Decision.DEFER_DENY,
|
decision__user__publish_data=True,
|
||||||
decision__user__publish_data=True,
|
),
|
||||||
),
|
),
|
||||||
),
|
count_defer_deny=Count(
|
||||||
count_deny=Count(
|
"decision",
|
||||||
"decision",
|
filter=Q(
|
||||||
filter=Q(
|
decision__admission_status=Decision.DEFER_DENY,
|
||||||
decision__admission_status=Decision.DENY,
|
decision__user__publish_data=True,
|
||||||
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):
|
def test_func(self):
|
||||||
return self.request.user.accepted_terms
|
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>
|
<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">
|
<div class="table-responsive">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<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">Total Applications</th>
|
||||||
<th scope="col">Admitted</th>
|
<th scope="col">Admitted</th>
|
||||||
<th scope="col">Waitlisted</th>
|
<th scope="col">Waitlisted</th>
|
||||||
|
@ -26,7 +46,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for college in object_list %}
|
{% for college in object_list %}
|
||||||
<tr>
|
<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_decisions }}</td>
|
||||||
<td>{{ college.count_admit }}</td>
|
<td>{{ college.count_admit }}</td>
|
||||||
<td>{{ college.count_waitlist }}</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>
|
<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 %}
|
{% if college or search_query %}
|
||||||
<p>Only showing students reporting applications to {{ college }}.</p>
|
<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 %}
|
{% 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">
|
<div class="table-responsive">
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -49,7 +65,7 @@
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</td>
|
</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>
|
<td>
|
||||||
{# Decisions #}
|
{# Decisions #}
|
||||||
<table class="table table-sm">
|
<table class="table table-sm">
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<p>You are about to delete this decision:</p>
|
<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">
|
<input type="submit" value="Confirm" class="btn btn-danger">
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
|
|
||||||
<p>You are about to delete this test score:</p>
|
<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">
|
<input type="submit" value="Confirm" class="btn btn-danger">
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user