feat(destinations): add count attending to college list

This commit is contained in:
Ethan Nguyen 2021-05-05 23:39:27 -04:00
parent 52d3276f45
commit efc7786916
No known key found for this signature in database
GPG Key ID: B4CA5339AF911920
3 changed files with 38 additions and 2 deletions

View File

@ -222,6 +222,7 @@ class DestinationsTest(TJDestsTestCase):
self.assertEqual(1, response.context["object_list"].count())
self.assertIn(college, response.context["object_list"])
self.assertEqual(1, response.context["object_list"][0].count_decisions)
self.assertEqual(0, response.context["object_list"][0].count_attending)
self.assertEqual(1, response.context["object_list"][0].count_admit)
self.assertEqual(0, response.context["object_list"][0].count_waitlist)
self.assertEqual(0, response.context["object_list"][0].count_waitlist_admit)
@ -242,17 +243,40 @@ class DestinationsTest(TJDestsTestCase):
make_senior=True,
publish_data=True,
)
Decision.objects.get_or_create(
decision = Decision.objects.get_or_create(
college=college,
user=user2,
decision_type="ED",
admission_status="WAITLIST_DENY",
)
)[0]
response = self.client.get(reverse("destinations:colleges"))
self.assertEqual(200, response.status_code)
self.assertEqual(1, response.context["object_list"].count())
self.assertIn(college, response.context["object_list"])
self.assertEqual(0, response.context["object_list"][0].count_attending)
self.assertEqual(2, response.context["object_list"][0].count_decisions)
self.assertEqual(1, response.context["object_list"][0].count_admit)
self.assertEqual(0, response.context["object_list"][0].count_waitlist)
self.assertEqual(0, response.context["object_list"][0].count_waitlist_admit)
self.assertEqual(1, response.context["object_list"][0].count_waitlist_deny)
self.assertEqual(0, response.context["object_list"][0].count_defer)
self.assertEqual(0, response.context["object_list"][0].count_defer_admit)
self.assertEqual(0, response.context["object_list"][0].count_defer_deny)
self.assertEqual(0, response.context["object_list"][0].count_defer_wl)
self.assertEqual(0, response.context["object_list"][0].count_defer_wl_admit)
self.assertEqual(0, response.context["object_list"][0].count_defer_wl_deny)
self.assertEqual(0, response.context["object_list"][0].count_deny)
# make user2 attend this college
user2.attending_decision = decision
user2.save()
response = self.client.get(reverse("destinations:colleges"))
self.assertEqual(200, response.status_code)
self.assertEqual(1, response.context["object_list"].count())
self.assertIn(college, response.context["object_list"])
self.assertEqual(1, response.context["object_list"][0].count_attending)
self.assertEqual(2, response.context["object_list"][0].count_decisions)
self.assertEqual(1, response.context["object_list"][0].count_admit)
self.assertEqual(0, response.context["object_list"][0].count_waitlist)

View File

@ -91,6 +91,15 @@ class CollegeDestinationListView(
count_decisions=Count(
"decision", filter=Q(decision__user__publish_data=True)
),
count_attending=Count(
"decision",
filter=Q(
decision__in=Decision.objects.filter(
attending_college__isnull=False
),
decision__user__publish_data=True,
),
),
count_admit=Count(
"decision",
filter=Q(

View File

@ -39,6 +39,7 @@
<tr>
<th scope="col">University Name, Location, CEEB code</th>
<th scope="col">Total Applications</th>
<th scope="col">Attending</th>
<th scope="col">Admitted</th>
<th scope="col">Waitlisted</th>
<th scope="col">Waitlist-Admitted</th>
@ -57,6 +58,7 @@
<tr>
<th scope="row"><a href="{% url "destinations:students" %}?college={{ college.id }}">{{ college }}</a></th>
<td>{{ college.count_decisions }}</td>
<td>{{ college.count_attending }}</td>
<td>{{ college.count_admit }}</td>
<td>{{ college.count_waitlist }}</td>
<td>{{ college.count_waitlist_admit }}</td>
@ -83,6 +85,7 @@
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
{% endfor %}
</tbody>