Skip to content

Commit

Permalink
Display election results in table
Browse files Browse the repository at this point in the history
- Includes turnout (ballot_papers_issued),
electorate, percentage turnout and spoilt ballots
  • Loading branch information
VirginiaDooley committed Sep 14, 2023
1 parent 36b8410 commit e74d390
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,46 @@ <h3>{% if postelection.is_london_assembly_additional %}{% trans "Additional memb
{% endif %}
</p>
{% endif %}

{% if postelection.election.in_past %}
<section class="ds-card">
<div class="ds-table">
<table>
<tr>
<th>Electorate</th>
<th>Turnout</th>
<th>Ballot Papers Issued</th>
<th>Spoilt Ballots</th>
</tr>
<tr>
<td>{% if postelection.election.electorate %}
{{ postelection.election.electorate }}
{% else %}
{% trans "Electorate not available" %}
{% endif %}
</td>
<td>{% if postelection.election.turnout %}
{{ postelection.election.turnout|stringformat:"d%%" }}
{% else %}
{% trans "Turnout not available" %}
{% endif %}
</td>
<td>{% if postelection.election.ballot_papers_issued %}
{{ postelection.election.ballot_papers_issued }}
{% else %}
{% trans "Number of ballot papers issued not available" %}
{% endif %}
</td>
<td>{% if postelection.election.spoilt_ballots %}
{{ postelection.election.spoilt_ballots }}
{% else %}
{% trans "Number of spoilt ballots not available" %}
{% endif %}
</td>
</tr>
</table>
</div>
</section>
{% 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 %}
Expand Down
16 changes: 16 additions & 0 deletions wcivf/apps/elections/tests/test_election_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import datetime
from random import shuffle

import factory
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit e74d390

Please sign in to comment.