Skip to content

add election timetable to schema#20

Merged
chris48s merged 3 commits into
mainfrom
timetable20260630
Jul 7, 2026
Merged

add election timetable to schema#20
chris48s merged 3 commits into
mainfrom
timetable20260630

Conversation

@chris48s

@chris48s chris48s commented Jun 30, 2026

Copy link
Copy Markdown
Member

This PR adds code to validate the timetable property in API responses and generate fake objects with a timetable.
This is needed to finish DemocracyClub/aggregator-api#642 and then we'll also want it when we move on to consuming the data in projects that parse/validate the API response.

Comment on lines +172 to +177
class Timetable(BaseModel):
notice_of_election_deadline: datetime.date = Field(default=None)
close_of_nominations: datetime.date = Field(default=None)
registration_deadline: datetime.date = Field(default=None)
postal_vote_application_deadline: datetime.date = Field(default=None)
vac_application_deadline: datetime.date = Field(default=None)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've already added notice_of_election_deadline here on the basis there is an open PR for it.
Just to avoid having to do too much cross-repo faffing about, I'd like to also think about the other dates we plan to add in the near future. Lets talk about this one in surgery tomorrow. One of the useful things about them defaulting to None is that pydantic will tolerate missing properties. For example, the test object I've added in tests/test_models.py lacks a notice_of_election_deadline property but it still validates. This means we can map out the other stuff we think we're going to add soon once, release a version, and it will tolerate those properties being missing until we add them.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Following discussion in surgery, the only other date we expect to add is sopn_publish_deadline so I've added that to the schema as well in 6a9a2ac

Comment on lines +17 to +23
def get_default_timetable(
ballot_paper_id: str, poll_date: str, requires_id: bool
):
"""
Generate a plausible-ish fake timetable
ignoring a lot of complexity and nuance
"""

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

A few notes on this:

  1. The builder library currently doesn't support provisional/date-less elections. So given we must have a poll date for any ballot it seems reasonable to auto-populate a timetable from that.
  2. One option here would be to pull in the timetable library to generate the timetable. However, I decided to go with not doing that and just creating some dates that are in the right sort of ballpark-ish. This is broadly in line with what we do elsewhere in this library. If we need a test object with specific or tediously correct dates then we can use the with_ methods for each timetable event.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The EC postcode pages relies on dates from the timetable library in it's mock responses. Let's make sure this works properly, and that they give sensible dates. We don't want EC people feeding back that the dates are wrong in that project (e.g it might say 'expect candidates after X date' but if X is made up here, that might be a problem). As you say, we can alter this when we make the mock data there, but let's make sure we're thinking about that case

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do they use the mock responses?
I thought they were only dev-facing.

@chris48s chris48s Jul 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just to explain my thinking more here: There plenty of obvious holes you could pick in the test data we generate to model various scenarios. For example:

Screenshot at 2026-07-02 15-13-44

is clearly not right, but as a test fixture, it is good enough to make sure the page is doing the right thing.

As long as we can fiddle dates to some point before and after the SOPN date to see what the page looks like before and after, its doing the job as well as it needs to, right.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If we can have number 10 in Manchester, we can have the Mayor of London in Stroud. It's not right, it's aspirational.

I guess we can talk about how they use those pages later, but the point of the site is to allow non-devs to see what the site looks like in various stages through an election. I guess if it becomes a problem we can always change how we make that data.

Comment thread response_builder/v1/builders/ballots.py Outdated
Comment on lines +26 to +27
if ballot_paper_id.startswith("ref."):
notice_of_election_deadline = None

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

TODO: change this if we change DemocracyClub/uk-election-timetables#61 (comment)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Following discussion in surgery:

notice_of_election_deadline is not implemented for referenda in the timetables lib, but we would be able to/expect to manually populate it in EE.

So when building a fake object, it makes sense to set a value.

Have done that in 0d461d2

@chris48s chris48s marked this pull request as ready for review July 2, 2026 08:09
@chris48s chris48s requested a review from symroe July 2, 2026 08:09

@symroe symroe left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One comment about the EC postcode pages. Also, let's get the SOPN dates in from the other PR before merging this.

@chris48s chris48s merged commit 3143f9f into main Jul 7, 2026
3 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