From efc7786916da1fcabdac5f5667ce3cb3fd1c43f2 Mon Sep 17 00:00:00 2001 From: Ethan Nguyen Date: Wed, 5 May 2021 23:39:27 -0400 Subject: [PATCH] feat(destinations): add count attending to college list --- tjdests/apps/destinations/tests.py | 28 +++++++++++++++++-- tjdests/apps/destinations/views.py | 9 ++++++ .../templates/destinations/college_list.html | 3 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/tjdests/apps/destinations/tests.py b/tjdests/apps/destinations/tests.py index ddcb323..abede51 100644 --- a/tjdests/apps/destinations/tests.py +++ b/tjdests/apps/destinations/tests.py @@ -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) diff --git a/tjdests/apps/destinations/views.py b/tjdests/apps/destinations/views.py index d869412..34bcf5e 100644 --- a/tjdests/apps/destinations/views.py +++ b/tjdests/apps/destinations/views.py @@ -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( diff --git a/tjdests/templates/destinations/college_list.html b/tjdests/templates/destinations/college_list.html index 27ef343..f6eea86 100644 --- a/tjdests/templates/destinations/college_list.html +++ b/tjdests/templates/destinations/college_list.html @@ -39,6 +39,7 @@ University Name, Location, CEEB code Total Applications + Attending Admitted Waitlisted Waitlist-Admitted @@ -57,6 +58,7 @@ {{ college }} {{ college.count_decisions }} + {{ college.count_attending }} {{ college.count_admit }} {{ college.count_waitlist }} {{ college.count_waitlist_admit }} @@ -83,6 +85,7 @@ + {% endfor %}