Skip to content

Commit

Permalink
Show results table only when data exists
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed Sep 14, 2023
1 parent b933119 commit b4d20ae
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
12 changes: 12 additions & 0 deletions wcivf/apps/elections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@ def pluralized_division_name(self):

return pluralise.get(suffix, f"{suffix}s")

@property
def has_results(self):
"""
Returns a boolean for if the election has results
"""
return bool(
self.spoilt_ballots
or self.ballot_papers_issued
or self.turnout
or self.electorate
)


class Post(models.Model):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ <h3>{% if postelection.is_london_assembly_additional %}{% trans "Additional memb
{% endif %}
</p>
{% endif %}
{% if postelection.election.in_past %}
{% if postelection.election.in_past and postelection.election.has_results %}
<section class="ds-card">
<div class="ds-table">
<table>
Expand All @@ -135,25 +135,25 @@ <h3>{% if postelection.is_london_assembly_additional %}{% trans "Additional memb
<td>{% if postelection.election.electorate %}
{{ postelection.election.electorate }}
{% else %}
{% trans "Electorate not available" %}
{% trans "None" %}
{% endif %}
</td>
<td>{% if postelection.election.turnout %}
{{ postelection.election.turnout|stringformat:"d%%" }}
{% else %}
{% trans "Turnout not available" %}
{% trans "None" %}
{% endif %}
</td>
<td>{% if postelection.election.ballot_papers_issued %}
{{ postelection.election.ballot_papers_issued }}
{% else %}
{% trans "Number of ballot papers issued not available" %}
{% trans "None" %}
{% endif %}
</td>
<td>{% if postelection.election.spoilt_ballots %}
{{ postelection.election.spoilt_ballots }}
{% else %}
{% trans "Number of spoilt ballots not available" %}
{% trans "None" %}
{% endif %}
</td>
</tr>
Expand Down
8 changes: 7 additions & 1 deletion wcivf/apps/elections/tests/test_election_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,12 +142,18 @@ def test_results_table(self):
"""check that the table containing the electorate,
turnout, spoilt ballots, ballot papers exist
for past elections"""
today = str(datetime.today().date())
self.election.electorate = 100
self.election.spoilt_ballots = 5
self.election.save()

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.assertTrue(self.post_election.election.has_results)
self.assertContains(response, "Electorate")
self.assertContains(response, "Turnout")
self.assertContains(response, "Spoilt Ballots")
Expand Down

0 comments on commit b4d20ae

Please sign in to comment.