Skip to content

Commit

Permalink
Update registration with new context
Browse files Browse the repository at this point in the history
-  Removes unused code
- Updates logic for council v registration
given change in context
- Reformats registration deadline date
- Fixes logic for is_before_registration_deadline
- Removes the advice about registering by post
- Fixes logic for past_registration_deadline to use datetime comparison
  • Loading branch information
VirginiaDooley committed May 23, 2024
1 parent e18c417 commit a8181a1
Show file tree
Hide file tree
Showing 9 changed files with 159 additions and 59 deletions.
1 change: 1 addition & 0 deletions wcivf/apps/elections/dummy_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class DummyPostElection(PostElection):
show_polling_card = True
contested = True
requires_voter_id = "EA-2022"
registration_deadline = date(2024, 6, 13)

election = Election(
name="Llantalbot local election",
Expand Down
9 changes: 7 additions & 2 deletions wcivf/apps/elections/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,13 +453,18 @@ def expected_sopn_date(self):

@property
def registration_deadline(self):
return get_election_timetable(
date = get_election_timetable(
self.ballot_paper_id, self.post.territory
).registration_deadline

return date.strftime("%d %B %Y")

@property
def past_registration_deadline(self):
return self.registration_deadline < datetime.date.today()
registration_deadline = get_election_timetable(
self.ballot_paper_id, self.post.territory
).registration_deadline
return registration_deadline < datetime.date.today()

@property
def postal_vote_application_deadline(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<address class="ds-stack-smallest">
{{ contact_details.name }}
{% if contact_details.address %}
{{ contact_details.address|linebreaksbr }}
{% endif %}
{% if contact_details.postcode %}
<br>{{ contact_details.postcode }}
<br>
{% endif %}
<p>
<address class="ds-stack-smallest">
{{ contact_details.name }}
{% if contact_details.address %}
{{ contact_details.address|linebreaksbr }}
{% endif %}
{% if contact_details.postcode %}
<br>{{ contact_details.postcode }}
<br>
{% endif %}

<a href="{{ contact_details.website }}">
{{ contact_details.website }}
</a>
<br><a href="mailto:{{ contact_details.email }}">{{ contact_details.email }}</a>
{% for number in contact_details.phone_numbers %}
<br><a href="tel:{{ number }}">{{ number }}</a>
{% endfor %}
</address>
<a href="{{ contact_details.website }}">
{{ contact_details.website }}
</a>
<br><a href="mailto:{{ contact_details.email }}">{{ contact_details.email }}</a>
{% for number in contact_details.phone_numbers %}
<br><a href="tel:{{ number }}">{{ number }}</a>
{% endfor %}
</address>
</p>
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,22 @@ <h2 id='register'>
</p>
{% if postelection %}
<p>
{% blocktrans trimmed with registration_deadline=postelection.registration_deadline election_date=postelection.election.election_date|date:"j M Y" %}
{% blocktrans trimmed with registration_deadline=postelection.registration_deadline|naturalday:"j F Y" election_date=postelection.election.election_date|naturalday:"j F Y" %}
Register before midnight on {{ registration_deadline }} to vote on {{ election_date }}.
{% endblocktrans %}
</p>
<p>
{% if council %}
{% if council.registration_contacts %}
{% blocktrans trimmed %}To register by post, contact your Valuation Joint Board.{% endblocktrans %}
{% else %}
{% blocktrans trimmed with council_name=council.name%}To register by post, contact {{ council_name }}.{% endblocktrans %}
{% endif %}
{% else %}
{% if postelection.post.territory == "SCT" %}
{% blocktrans trimmed %}To register by post, contact your Valuation Joint Board.{% endblocktrans %}
{% else %}
{% blocktrans trimmed%}To register by post, contact your local council.{% endblocktrans %}
{% endif %}
{% endif %}

</p>
{% endif %}
{% if council.council_id %}
<!-- valid only for Scottish postcodes -->
{% if council.registration_contacts %}
{% include "elections/includes/_council_contact_details.html" with contact_details=council.registration_contacts %}

<p>
{% blocktrans trimmed %}
For questions about your poll card, polling place, or about returning your postal voting ballot, contact your council.
{% endblocktrans %}
</p>

<p>
{% blocktrans trimmed %}
For questions about your poll card, polling place, or about returning your postal voting ballot, contact your council.
{% endblocktrans %}
</p>
{% if registration %}
{% include "elections/includes/_council_contact_details.html" with contact_details=registration %}
{% endif %}

{% include "elections/includes/_council_contact_details.html" with contact_details=council.electoral_services_contacts %}


{% include "elections/includes/_council_contact_details.html" with contact_details=council %}
{% endif %}

</details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
{% endif %}

{% if is_before_registration_deadline %}
{% include "elections/includes/_registration_details.html" with postelection=postelections.first council=polling_station.council %}
{% include "elections/includes/_registration_details.html" with postelection=postelections.0 council=council %}
{% endif %}

{% if not messages %}
Expand Down
1 change: 0 additions & 1 deletion wcivf/apps/elections/tests/test_election_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ def test_previous_cancelled_elections(self):
self.post_election.cancelled = True
self.post_election.save()
response = self.client.get(self.person.get_absolute_url(), follow=True)
# import pdb; pdb.set_trace()
self.assertContains(response, "{}'s elections".format(self.person.name))
self.assertContains(response, "(election cancelled")

Expand Down
111 changes: 106 additions & 5 deletions wcivf/apps/elections/tests/test_postcode_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,12 @@ def mock_response(self, mocker):
individual tests can then add json data to
"""
response = mocker.MagicMock(status_code=200)
response.json.return_value = {"address_picker": False, "dates": []}
response.json.return_value = {
"address_picker": False,
"dates": [],
"electoral_services": {},
"registration": {},
}
mocker.patch(
"requests.get",
return_value=response,
Expand All @@ -164,6 +169,7 @@ def test_city_of_london_today(self, mock_response, client):
ballot_paper_id="local.city-of-london.aldgate.2021-05-06",
election__slug="local.city-of-london.2021-05-06",
election__election_date="2021-05-06",
post__territory="ENG",
)

mock_response.json.return_value["dates"].append(
Expand Down Expand Up @@ -227,24 +233,29 @@ def test_not_today(self, mock_response, client):
response, "Polling stations are open from 8a.m. till 8p.m. today"
)

@pytest.mark.django_db
@freeze_time("2024-05-23")
def test_multiple_elections_london(self, mock_response, client):
"""This test is for the case where there are multiple elections in
London on the same day and we want to make sure that the correct
polling station opening times are displayed for each election
as well as the correct anchor links to the election pages
"""
local_london = PostElectionFactory(
ballot_paper_id="local.city-of-london.aldgate.2021-05-06",
ballot_paper_id="local.city-of-london.aldgate.2024-05-06",
election__slug="local.city-of-london.2024-05-06",
election__election_date="2024-05-06",
election__name="City of London Corporation local election",
)

parl_london = PostElectionFactory(
ballot_paper_id="parl.cities-of-london-and-westminster.by.2021-05-06",
ballot_paper_id="parl.cities-of-london-and-westminster.by.2024-05-06",
election__slug="parl.2024-05-06",
election__election_date="2024-05-06",
election__name="Cities of London and Westminster by-election",
)
parl_london.is_before_registration_deadline = True
local_london.is_before_registration_deadline = True

mock_response.json.return_value["dates"].extend(
[
Expand Down Expand Up @@ -360,7 +371,11 @@ def test_no_polling_station_shows_council_details(
ballot_paper_id="local.sheffield.ecclesall.2021-05-06",
election__slug="local.sheffield.2021-05-06",
election__election_date="2021-05-06",
post__territory="ENG",
)

local.is_before_registration_deadline = True

mock_response.json.return_value["dates"].extend(
[
{
Expand All @@ -371,14 +386,100 @@ def test_no_polling_station_shows_council_details(
]
)

mock_response.json.return_value["electoral_services"].update(
{
"council_id": "W06000015",
"name": "Cardiff Council",
"nation": "Wales",
"address": "Electoral Registration Officer\\nCity of Cardiff Council\\nCounty Hall Atlantic Wharf",
"postcode": "CF10 4UW",
"email": "[email protected]",
"phone": "029 2087 2034",
"website": "http://www.cardiff.gov.uk/",
}
)

response = client.get(
reverse("postcode_view", kwargs={"postcode": "TE11ST"}), follow=True
reverse(
"postcode_view",
kwargs={
"postcode": "TE11ST",
},
),
follow=True,
)

assert response.status_code == 200
assert response.context["council"] is not None

asserts.assertContains(
response,
"Cardiff Council",
)

def council_and_registration_details_differ(self, mock_response, client):
"""When council contact details are different from
the registration details, show both."""
local = PostElectionFactory(
ballot_paper_id="local.sheffield.ecclesall.2021-05-06",
election__slug="local.sheffield.2021-05-06",
election__election_date="2021-05-06",
post__territory="ENG",
)

local.is_before_registration_deadline = True

mock_response.json.return_value["dates"].extend(
[
{
"date": local.election.election_date,
"polling_station": {"polling_station_known": False},
"ballots": [{"ballot_paper_id": local.ballot_paper_id}],
},
]
)

mock_response.json.return_value["electoral_services"].update(
{
"council_id": "W06000015",
"name": "Cardiff Council",
"nation": "Wales",
"address": "City of Cardiff Council\\nCounty Hall Atlantic Wharf",
"postcode": "CF10 4UW",
"email": "[email protected]",
"phone": "029 2087 2034",
"website": "http://www.cardiff.gov.uk/",
}
)

mock_response.json.return_value["registration"].update(
{
"address": "Electoral Registration Officer\\nCity of Cardiff Council\\nCounty Hall Atlantic Wharf",
"postcode": "CF10 4UW",
"email": "[email protected]",
"phone": "029 2087 2034",
"website": "http://www.cardiff.gov.uk/",
}
)
response = client.get(
reverse(
"postcode_view",
kwargs={
"postcode": "TE11ST",
},
),
follow=True,
)

assert response.status_code == 200
assert response.context["registration"] is not None

asserts.assertContains(
response,
"""You should get a "poll card" through the post telling you where to vote.""",
"Electoral Registration Officer",
)
asserts.assertContains(response, "[email protected]")
asserts.assertContains(response, "[email protected]")


class TestPostcodeViewMethods:
Expand Down
11 changes: 10 additions & 1 deletion wcivf/apps/elections/views/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def postcode_to_ballots(self, postcode, uprn=None, compact=False):
ret = {
"address_picker": results_json["address_picker"],
"polling_station": {},
"electoral_services": results_json["electoral_services"],
}

if ret["address_picker"]:
ret["addresses"] = results_json["addresses"]
return ret
Expand Down Expand Up @@ -163,9 +165,16 @@ def is_before_registration_deadline(self, post_elections):
return False
election = post_elections[0].election
country = post_elections[0].post.territory

if not country:
country = Country.ENGLAND

else:
country = {
"ENG": Country.ENGLAND,
"SCT": Country.SCOTLAND,
"WLS": Country.WALES,
"NIR": Country.NORTHERN_IRELAND,
}.get(country)
election = from_election_id(election_id=election.slug, country=country)
event = TimetableEvent.REGISTRATION_DEADLINE
return election.is_before(event)
Expand Down
8 changes: 6 additions & 2 deletions wcivf/apps/elections/views/postcode_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ def get_context_data(self, **kwargs):
context["show_polling_card"] = self.show_polling_card(
context["postelections"]
)
context["is_before_registration_deadline"] = (
self.is_before_registration_deadline(context["postelections"])
)
context["people_for_post"] = {}
for postelection in context["postelections"]:
postelection.people = self.people_for_ballot(postelection)
context["polling_station"] = self.ballot_dict.get("polling_station")
context["council"] = self.ballot_dict.get("electoral_services")
context["registration"] = self.ballot_dict.get("registration")

context["advance_voting_station"] = (
self.get_advance_voting_station_info(context["polling_station"])
)
Expand All @@ -106,7 +110,7 @@ def get_context_data(self, **kwargs):
def future_postelections(self, postelections):
"""
Given a list of postelections, check if any of them are in the future
and return a list of those that are
and return True if so.
"""
return any(
postelection
Expand Down Expand Up @@ -350,7 +354,7 @@ def get_context_data(self, **kwargs):
context["is_before_registration_deadline"] = (
PostcodeView().is_before_registration_deadline(context["postelections"])
)
context["electoral_services"] = self.get_registration()
context["registration"] = self.get_registration()
context["council"] = self.get_electoral_services()
context["requires_voter_id"] = "EA-2022"
context["num_ballots"] = 1
Expand Down

0 comments on commit a8181a1

Please sign in to comment.