Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

City of London registration info #108

Merged
merged 7 commits into from
Nov 4, 2024
Merged

City of London registration info #108

merged 7 commits into from
Nov 4, 2024

Conversation

chris48s
Copy link
Member

@chris48s chris48s commented Oct 30, 2024

Refs https://app.asana.com/0/1204880927741389/1208540419887296/f
Refs DemocracyClub/WhoCanIVoteFor#2071

City of London has different registration rules to everywhere else in the country.
The point of this PR is to show people the correct "register to vote" information.

The starting point for this PR is that we were showing a register to vote Call To Action against every date. For various reasons, I've stuck with showing the registration info at date level rather than moving it to the ballot. We'll show the gov.uk/register-to-vote CTA at most once per date with upcoming elections and the City of London CTA at most once.

In terms of testing this locally, you can check the various "standard" fixtures continue to work.
I've also added a couple of specific mock data cases for testing City of London with some other ballot.
The really juicy one is 2 ballots on the same day (one City of London, one not).
Within that, there are 3 sub-cases:

Both ballots are before the registration deadline:
http://127.0.0.1:8000/mock/polling-stations?postcode-search=AA1%201AM&baseline_date=2025-12-04

One ballot is before the registration deadline and one is after
http://127.0.0.1:8000/mock/polling-stations?postcode-search=AA1%201AM&baseline_date=2024-11-19

Both ballots after the registration deadline
http://127.0.0.1:8000/mock/polling-stations?postcode-search=AA1%201AM&baseline_date=2024-11-05

I think I've managed to make all 3 work nicely.

side notes:
This PR took a really long time. It probably isn't obvious from the finished code, but I had to try a bunch of stuff that didn't work before finding the thing that did :D

I think one of the things we might need to look at on this codebase is making it easier to pass additional information about individual ballots through to the template layer beyond the exact fields returned by the API. At the moment, if you want to do something like give a ballot an is_city_london property, or attach a custom timetable object to a ballot (for example), you can't do it because:

  1. Pydantic is very strict. You can't just monkey path an additional property or method that doesn't match the schema onto it. This is good in some ways but it can also be a limitation.
  2. The current code just pases the pydantic models straight into the template layer.

I reckon we might end up wanting a way to pass additional context for an individual ballot, but its more of an extensive refactor.

That isn't really actionable for this review. Just something I hit while I was working on this.

@chris48s chris48s force-pushed the col-registration20241030 branch from 0857a72 to 2594c7a Compare October 30, 2024 15:55
Comment on lines -154 to +158
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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a little issue I fixed while I was here.
Previously if htag was h3 we'd render the next heading as a h3 too

@@ -162,7 +165,34 @@ def toc_label(self):

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

voter-registration was already not a unique ID, and even less-so now.

I think this should make it unique

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually realised when I came back to this we need to account for both polling day and the registration deadline to ensure uniqueness

6d8956b

template_name = "includes/registration_timetable_col.html"

def __init__(self, *args, **kwargs) -> None:
self.with_headers = kwargs.pop("with_headers")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically: If we're showing 2 "register to vote" CTAs, we need a way to say "don't show the headers on the second one"

@@ -199,7 +229,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")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declaring this out of scope for this PR 🏃

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

@chris48s chris48s Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we were making a list of classes and then constructing them all into objects at the end with the same kwargs.

I've switched to constructing objects as I go. This allows me to pass in custom timetable into each registration section instead of having on global one.

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 %}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't updated any translations in this PR. See #110

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, all this text is open to change if it needs it. I've mostly used the same text Peter gave me that we used in DemocracyClub/WhoCanIVoteFor#2071

@@ -33,3 +40,46 @@ def uvicorn_server():
time.sleep(0.3)
yield f"http://localhost:{port}"
proc.kill()


@pytest.fixture
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I am just moving these fixtures into conftest.py so we can use them in multiple files.

return [s for s in sections if type(s) == type_]


@freeze_time("2024-04-16")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't really enough tests bth, but it is better than a kick in the teeth

@chris48s chris48s marked this pull request as ready for review October 30, 2024 16:23
@chris48s chris48s changed the title WIP City of London registration info City of London registration info Oct 30, 2024
@chris48s chris48s requested a review from symroe October 30, 2024 16:24
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: I first read this as "column" not "City Of London". Would you mind calling this registration_timetable_city-of-london.html?

@chris48s chris48s merged commit 6fdc644 into main Nov 4, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants