Skip to content

Commit

Permalink
show user City of London registration info
Browse files Browse the repository at this point in the history
show the user correct 'register to vote'
information for both
- CoL local elections
- everywhere else
  • Loading branch information
chris48s committed Oct 30, 2024
1 parent 0c41884 commit 0b8fb4a
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 19 deletions.
92 changes: 79 additions & 13 deletions postcode_lookup/template_sorter.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,12 @@ def context(self):
context["can_register_vac"] = self.timetable.is_before(
TimetableEvent.VAC_APPLICATION_DEADLINE
)
context["htag"] = "h2"
context["htag_primary"] = "h2"
context["htag_secondary"] = "h3"
if self.response_type == ResponseTypes.MULTIPLE_DATES:
context["htag"] = "h3"
context["htag_primary"] = "h3"
context["htag_secondary"] = "h4"
context["toc_id"] = self.toc_id
return context

@property
Expand All @@ -162,7 +165,38 @@ def toc_label(self):

@property
def toc_id(self):
return "voter-registration"
return f"voter-registration-{self.timetable.registration_deadline}"


class CityOfLondonRegistrationDateSection(RegistrationDateSection):
template_name = "includes/registration_timetable_col.html"

def __init__(self, *args, **kwargs) -> None:
self.with_headers = kwargs.pop("with_headers")
super().__init__(*args, **kwargs)

@property
def weight(self):
if self.timetable.is_before(TimetableEvent.REGISTRATION_DEADLINE):
return -5999

if self.timetable.is_after(TimetableEvent.REGISTRATION_DEADLINE):
return 1002
return 0

@property
def context(self):
context = super().context
context["with_headers"] = self.with_headers
return context

@property
def toc_label(self):
return _("Voter registration")

@property
def toc_id(self):
return f"voter-registration-col-{self.timetable.registration_deadline}"


class ElectionDateTemplateSorter:
Expand Down Expand Up @@ -199,7 +233,7 @@ def __init__(

self.polling_station_opening_times_str = _("7am – 10pm")
if any(
"city-of-london" in ballot.ballot_paper_id
ballot.ballot_paper_id.startswith("local.city-of-london.")
for ballot in self.date_data.ballots
):
self.polling_station_opening_times_str = _("8am – 8pm")
Expand All @@ -217,18 +251,50 @@ def __init__(
"timetable": self.timetable,
}

enabled_sections = [BallotSection]
if not self.all_cancelled:
enabled_sections.append(RegistrationDateSection)
enabled_sections = [BallotSection(**section_kwargs)]

city_of_london_ballots = [
b
for b in self.date_data.ballots
if not b.cancelled
and b.ballot_paper_id.startswith("local.city-of-london.")
]
other_ballots = [
b
for b in self.date_data.ballots
if not b.cancelled
and not b.ballot_paper_id.startswith("local.city-of-london.")
]
if len(other_ballots) > 0:
enabled_sections.append(
RegistrationDateSection(
data=self.date_data,
mode=self.current_mode,
response_type=self.response_type,
current_date=self.current_date,
timetable=from_election_id(
other_ballots[0].election_id, country=country
),
)
)
if len(city_of_london_ballots) > 0:
enabled_sections.append(
CityOfLondonRegistrationDateSection(
data=self.date_data,
mode=self.current_mode,
response_type=self.response_type,
current_date=self.current_date,
timetable=from_election_id(
city_of_london_ballots[0].election_id, country=country
),
with_headers=len(other_ballots) == 0,
)
)

if self.first_upcoming_date:
enabled_sections.append(PollingStationSection)
enabled_sections.append(PollingStationSection(**section_kwargs))

self.sections = sorted(
[section(**section_kwargs) for section in enabled_sections],
key=lambda sec: sec.weight,
# reverse=True,
)
self.sections = sorted(enabled_sections, key=lambda sec: sec.weight)


class TemplateSorter:
Expand Down
23 changes: 17 additions & 6 deletions postcode_lookup/templates/includes/registration_timetable.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
<{{ section.context.htag }} id="voter-registration">{% trans %}Voter registration{% endtrans %}</{{ section.context.htag }}>
<{{ section.context.htag_primary }} id="{{toc_id}}">{% trans %}Voter registration{% endtrans %}</{{ section.context.htag_primary }}>
{% if section.context.can_register %}
<h3>Register to vote</h3>
<p>You have until {{ section.timetable.registration_deadline|date_filter }}</p>
<p><a href="https://gov.uk/register-to-vote/" class="o-button o-button--primary o-button--dark o-external-link">
Register to vote</a></p>
<{{ section.context.htag_secondary }}>{% trans %}Register to vote{% endtrans %}</{{ section.context.htag_secondary }}>
<p>
{% trans date=section.timetable.registration_deadline|date_filter %}
You have until {{ date }}
{% endtrans %}
</p>
<p>
<a href="https://gov.uk/register-to-vote/" class="o-button o-button--primary o-button--dark o-external-link">
{% trans %}Register to vote{% endtrans %}
</a>
</p>
{% else %}
{% trans date=section.data.date|date_filter, registration_deadline=section.timetable.registration_deadline|date_filter %}
{%
trans
date=section.data.date|date_filter,
registration_deadline=section.timetable.registration_deadline|date_filter
%}
<p>The deadline to register to vote on {{ date }}
was {{ registration_deadline }}.</p>
<p>If you registered to vote before the deadline, then you will be able to vote in this election. <a
Expand Down
36 changes: 36 additions & 0 deletions postcode_lookup/templates/includes/registration_timetable_col.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{% if section.context.with_headers %}
<{{ section.context.htag_primary }} id="{{toc_id}}">{% trans %}Voter registration{% endtrans %}</{{ section.context.htag_primary }}>
{% endif %}
{% if section.context.can_register %}
{% if section.context.with_headers %}
<{{ section.context.htag_secondary }}>{% trans %}Register to vote{% endtrans %}</{{ section.context.htag_secondary }}>
{% endif %}
<p>{% trans %}City of London council elections do not use the same electoral register as other elections.{% endtrans %}</p>
<p>
{% trans %}
Both residents and city workers are eligible to vote. There is one register
published annually, and the deadline to apply is 30 November each year.
The new register comes into force on 16 February each year,
and cannot be modified after that date.
{% endtrans %}
</p>
<p>
<a href="https://www.speakforthecity.com/" class="o-button o-button--primary o-button--dark o-external-link">
{% trans %}Register to vote in the City of London{% endtrans %}
</a>
</p>
{% else %}
<{{ section.context.htag_secondary }} id="{{toc_id}}">{% trans %}Registration in the City of London{% endtrans %}</{{ section.context.htag_secondary }}>
<p>{% trans %}City of London council elections do not use the same electoral register as other elections.{% endtrans %}</p>
{%
trans
date=section.data.date|date_filter,
registration_deadline=section.timetable.registration_deadline|date_filter
%}
<p>The deadline to register to vote in City of London local elections on {{ date }}
was {{ registration_deadline }}.</p>
<p>If you registered to vote before the deadline, then you will be able to vote in this election. <a
href="#electoral_services">Contact City of London</a> to check if you are on the register.</p>
<p>You can <a href="https://www.speakforthecity.com/">register to vote in the City of London</a> in future elections.</p>
{% endtrans %}
{% endif %}

0 comments on commit 0b8fb4a

Please sign in to comment.