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 18, 2023
1 parent 2260237 commit cd4b408
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 47 deletions.
75 changes: 54 additions & 21 deletions locale/cy/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-08-01 17:19+0100\n"
"POT-Creation-Date: 2023-09-18 18:19+0100\n"
"PO-Revision-Date: 2022-03-24 09:04+0000\n"
"Last-Translator: Sym Roe <[email protected]>, 2022\n"
"Language-Team: Welsh (https://www.transifex.com/democracy-club/teams/61326/"
Expand All @@ -29,21 +29,21 @@ msgstr ""
msgid "Enter your postcode"
msgstr "Rhowch eich cod post"

#: wcivf/apps/elections/models.py:656
#: wcivf/apps/elections/models.py:672
msgid "First-past-the-post"
msgstr "Y Cyntaf i’r Felin"

#: wcivf/apps/elections/models.py:658
#: wcivf/apps/elections/models.py:674
#, fuzzy
#| msgid "The Additional Member System"
msgid "Additional Member System"
msgstr "Y System Aelodau Ychwanegol"

#: wcivf/apps/elections/models.py:660
#: wcivf/apps/elections/models.py:676
msgid "Supplementary Vote"
msgstr "Pleidlais Atodol"

#: wcivf/apps/elections/models.py:662
#: wcivf/apps/elections/models.py:678
msgid "Single Transferable Vote"
msgstr "Pleidlais Sengl Drosglwyddadwy"

Expand Down Expand Up @@ -752,40 +752,58 @@ msgstr ""
"helpu i wella'r dudalen hon: <a href=\"%(ynr_link)s\"> ychwanegwch wybodaeth "
"am ymgeiswyr i'n cronfa ddata</a>."

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:130
#, fuzzy
#| msgid "Elected"
msgid "Electorate"
msgstr "Etholwyd"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:133
msgid "Turnout"
msgstr "Canran y Pleidleiswyr"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:136
msgid "Ballot Papers Issued"
msgstr "Nifer y Papurau Pleidleisio a Gyhoeddwyd"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:139
msgid "Spoilt Ballots"
msgstr "Pleidleisiau Difetha"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:174
#, python-format
msgid ""
"The <a href=\"%(sopn_url)s\">official candidate list</a> has been published."
msgstr ""
"Mae'r <a href=\"%(sopn_url)s\">rhestr swyddogol o ymgeiswyr</a> wedi'i "
"chyhoeddi."

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:141
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:179
msgid "The official candidate list should have been published on"
msgstr "Dylai'r rhestr swyddogol o ymgeiswyr fod wedi'i chyhoeddi ar "

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:143
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:181
msgid "The official candidate list should be published on"
msgstr "Dylai'r rhestr swyddogol o ymgeiswyr gael ei chyhoeddi ar"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:151
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:189
msgid "Read the official candidate booklet for this election."
msgstr "Darllenwch y llyfryn ymgeiswyr swyddogol ar gyfer yr etholiad hwn."

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:155
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:193
#, python-format
msgid " %(description)s "
msgstr " %(description)s "

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:163
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:201
msgid "Can you vote in this election?"
msgstr "A allwch chi bleidleisio yn yr etholiad hwn?"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:164
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:202
msgid "Age"
msgstr "Oedran"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:166
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:204
#, python-format
msgid ""
"You need to be over %(voter_age)s on the %(voter_age_date)s of "
Expand All @@ -794,16 +812,16 @@ msgstr ""
"Mae angen i chi fod dros %(voter_age)s ar %(voter_age_date)s "
"%(election_date)s i bleidleisio yn yr etholiad hwn."

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:171
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:209
msgid "Citizenship"
msgstr "Dinasyddiaeth"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:191
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:229
#: wcivf/apps/people/templates/people/includes/_person_about_card.html:9
msgid "Wikipedia"
msgstr "Wikipedia"

#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:193
#: wcivf/apps/elections/templates/elections/includes/_single_ballot.html:231
#: wcivf/apps/people/templates/people/includes/_person_about_card.html:11
msgid "Read more on Wikipedia"
msgstr "Darllenwch fwy ar Wikipedia"
Expand Down Expand Up @@ -1784,11 +1802,6 @@ msgstr ""
msgid "Position"
msgstr ""

#: wcivf/apps/people/templates/people/includes/_person_previous_elections_card.html:25
#, python-format
msgid "%(post_label)s: %(election)s"
msgstr "%(post_label)s: %(election)s"

#: wcivf/apps/people/templates/people/includes/intros/_constituency.html:5
#, python-format
msgid ""
Expand Down Expand Up @@ -1971,7 +1984,7 @@ msgstr "Llun proffil %(object.name)s"
msgid "You are here:"
msgstr "Rydych chi yma:"

#: wcivf/apps/people/templates/people/person_detail.html:58
#: wcivf/apps/people/templates/people/person_detail.html:60
msgid "Back to candidates in"
msgstr "Dychwelyd at ymgeiswyr yn"

Expand Down Expand Up @@ -2173,6 +2186,26 @@ msgstr "Etholiadau i ddod"
msgid "Join our mailing list"
msgstr "Ymunwch â'n rhestr bostio"

#, fuzzy
#~| msgid "Elected (vote count not available)"
#~ msgid "Electorate not available"
#~ msgstr "Etholwyr ddim ar gael"

#, fuzzy
#~| msgid "Elected (vote count not available)"
#~ msgid "Turnout not available"
#~ msgstr "Nid yw'r cyfrif pleidleisiau ar gael"

#~ msgid "Number of ballot papers issued not available"
#~ msgstr "Nid yw nifer y papurau pleidleisio a roddwyd ar gael"

#~ msgid "Number of spoilt ballots not available"
#~ msgstr "Nifer y pleidleisiau a ddifethwyd ddim ar gael"

#, python-format
#~ msgid "%(post_label)s: %(election)s"
#~ msgstr "%(post_label)s: %(election)s"

#~ msgid "Where do I vote?"
#~ msgstr "Ble rydw i'n pleidleisio?"

Expand Down
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,41 +121,40 @@ <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>
<tr>
<th>Electorate</th>
<th>Turnout</th>
<th>Ballot Papers Issued</th>
<th>Spoilt Ballots</th>
{% if postelection.election.electorate %}
<th>{% trans "Electorate" %}</th>
{% endif %}
{% if postelection.election.turnout %}
<th>{% trans "Turnout" %} </th>
{% endif %}
{% if postelection.election.ballot_papers_issued %}
<th>{% trans "Ballot Papers Issued" %}</th>
{% endif %}
{% if postelection.election.spoilt_ballots %}
<th>{% trans "Spoilt Ballots" %}</th>
{% endif %}
</tr>
<tr>
<td>{% if postelection.election.electorate %}
{{ postelection.election.electorate }}
{% else %}
{% trans "Electorate not available" %}
{% if postelection.election.electorate %}
<td>{{ postelection.election.electorate }}</td>
{% endif %}
</td>
<td>{% if postelection.election.turnout %}
{{ postelection.election.turnout|stringformat:"d%%" }}
{% else %}
{% trans "Turnout not available" %}

{% if postelection.election.turnout %}
<td>{{ postelection.election.turnout|stringformat:"d%%" }}</td>
{% endif %}
</td>
<td>{% if postelection.election.ballot_papers_issued %}
{{ postelection.election.ballot_papers_issued }}
{% else %}
{% trans "Number of ballot papers issued not available" %}

{% if postelection.election.ballot_papers_issued %}
<td>{{ postelection.election.ballot_papers_issued }}</td>
{% endif %}
</td>
<td>{% if postelection.election.spoilt_ballots %}
{{ postelection.election.spoilt_ballots }}
{% else %}
{% trans "Number of spoilt ballots not available" %}

{% if postelection.election.spoilt_ballots %}
<td>{{ postelection.election.spoilt_ballots }}</td>
{% endif %}
</td>
</tr>
</table>
</div>
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 cd4b408

Please sign in to comment.