From e74d390e0241eb28a0c748d925bfe1adb25dfbd4 Mon Sep 17 00:00:00 2001
From: Virginia Dooley
Date: Thu, 24 Aug 2023 11:16:30 +0100
Subject: [PATCH] Display election results in table
- Includes turnout (ballot_papers_issued),
electorate, percentage turnout and spoilt ballots
---
.../elections/includes/_single_ballot.html | 41 ++++++++++++++++++-
.../elections/tests/test_election_views.py | 16 ++++++++
2 files changed, 56 insertions(+), 1 deletion(-)
diff --git a/wcivf/apps/elections/templates/elections/includes/_single_ballot.html b/wcivf/apps/elections/templates/elections/includes/_single_ballot.html
index 297080a20..9780500bd 100644
--- a/wcivf/apps/elections/templates/elections/includes/_single_ballot.html
+++ b/wcivf/apps/elections/templates/elections/includes/_single_ballot.html
@@ -121,7 +121,46 @@ {% if postelection.is_london_assembly_additional %}{% trans "Additional memb
{% endif %}
{% endif %}
-
+ {% if postelection.election.in_past %}
+
+
+
+
+ Electorate |
+ Turnout |
+ Ballot Papers Issued |
+ Spoilt Ballots |
+
+
+ {% if postelection.election.electorate %}
+ {{ postelection.election.electorate }}
+ {% else %}
+ {% trans "Electorate not available" %}
+ {% endif %}
+ |
+ {% if postelection.election.turnout %}
+ {{ postelection.election.turnout|stringformat:"d%%" }}
+ {% else %}
+ {% trans "Turnout not available" %}
+ {% endif %}
+ |
+ {% if postelection.election.ballot_papers_issued %}
+ {{ postelection.election.ballot_papers_issued }}
+ {% else %}
+ {% trans "Number of ballot papers issued not available" %}
+ {% endif %}
+ |
+ {% if postelection.election.spoilt_ballots %}
+ {{ postelection.election.spoilt_ballots }}
+ {% else %}
+ {% trans "Number of spoilt ballots not available" %}
+ {% endif %}
+ |
+
+
+
+
+ {% endif %}
{% if postelection.people and postelection.should_show_candidates %}
{% if postelection.display_as_party_list %}
{% include "elections/includes/_people_list_with_lists.html" with people=postelection.people %}
diff --git a/wcivf/apps/elections/tests/test_election_views.py b/wcivf/apps/elections/tests/test_election_views.py
index b8b8d6a76..d6c2498f9 100644
--- a/wcivf/apps/elections/tests/test_election_views.py
+++ b/wcivf/apps/elections/tests/test_election_views.py
@@ -1,3 +1,4 @@
+from datetime import datetime
from random import shuffle
import factory
@@ -137,6 +138,21 @@ def setUp(self):
election=self.election, post=self.post
)
+ def test_results_table(self):
+ """check that the table containing the electorate,
+ turnout, spoilt ballots, ballot papers exist
+ for past elections"""
+ response = self.client.get(
+ self.post_election.get_absolute_url(), follow=True
+ )
+ self.assertEqual(response.status_code, 200)
+ today = str(datetime.today().date())
+ self.assertLess(self.election.election_date, today)
+ self.assertContains(response, "Electorate")
+ self.assertContains(response, "Turnout")
+ self.assertContains(response, "Spoilt Ballots")
+ self.assertContains(response, "Ballot Papers Issued")
+
def test_zero_candidates(self):
response = self.client.get(
self.post_election.get_absolute_url(), follow=True