-
Notifications
You must be signed in to change notification settings - Fork 19
add Proxy Vote Application Deadline and Replacement Pack Start Date to calendar #2624
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
Draft
chris48s
wants to merge
10
commits into
master
Choose a base branch
from
moardates20260813
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+479
−6
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6ebc0c6
fix a few mistakes in comments
chris48s a6dc3ca
calculate proxy vote application deadline
chris48s 7d2b788
update package tests
chris48s 7d251b3
add proxy vote deadline to election model
chris48s 5fb72bc
update application tests
chris48s 70f0836
calculate postal vote replacement pack start date
chris48s d74b06a
update package tests
chris48s 5d286f1
add postal vote replacement pack start date to election model
chris48s 45a9385
update application tests
chris48s cec9fab
add backfill migration to populate new fields
chris48s File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
every_election/apps/elections/migrations/0091_election_proxy_vote_application_deadline.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Generated by Django 5.2.16 on 2026-08-13 06:56 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("elections", "0090_backfill_new_timetable_fields"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="election", | ||
| name="proxy_vote_application_deadline", | ||
| field=models.DateField( | ||
| blank=True, | ||
| help_text="Proxy vote application deadline", | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
21 changes: 21 additions & 0 deletions
21
every_election/apps/elections/migrations/0092_election_replacement_pack_start_date.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Generated by Django 5.2.16 on 2026-08-13 09:55 | ||
|
|
||
| from django.db import migrations, models | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("elections", "0091_election_proxy_vote_application_deadline"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.AddField( | ||
| model_name="election", | ||
| name="replacement_pack_start_date", | ||
| field=models.DateField( | ||
| blank=True, | ||
| help_text="First date electors can apply for a postal vote replacement pack", | ||
| null=True, | ||
| ), | ||
| ), | ||
| ] |
84 changes: 84 additions & 0 deletions
84
every_election/apps/elections/migrations/0093_backfill_new_timetable_fields.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # Generated by Django 5.2.13 on 2026-06-16 10:30 | ||
|
|
||
| from django.db import migrations | ||
| from uk_election_timetables.calendars import Country | ||
| from uk_election_timetables.election_ids import from_election_id | ||
|
|
||
| country_map = { | ||
| "WLS": Country.WALES, | ||
| "ENG": Country.ENGLAND, | ||
| "NIR": Country.NORTHERN_IRELAND, | ||
| "SCT": Country.SCOTLAND, | ||
| "GBN": None, | ||
| } | ||
|
|
||
|
|
||
| def backfill_new_timetable_fields(apps, schema_editor): | ||
| Election = apps.get_model("elections", "Election") | ||
| qs = ( | ||
| Election.private_objects.using(schema_editor.connection.alias) | ||
| # we can't calculate a timetable for an election with no polling day | ||
| .filter(poll_open_date__isnull=False) | ||
| # only calculate a timetable for ballots | ||
| .filter(group_type__isnull=True) | ||
| # We don't have logic for computing timetable for | ||
| # EU Parliament elections but some do exist in the DB | ||
| # from back in the day | ||
| .exclude(election_id__startswith="europarl.") | ||
| .select_related("division", "organisation") | ||
| ) | ||
|
|
||
| elections_to_update = [] | ||
|
|
||
| for election in qs.iterator(): | ||
| area = election.division or election.organisation | ||
| territory_code = ( | ||
| area.territory_code or election.organisation.territory_code | ||
| ) | ||
|
|
||
| timetable = from_election_id( | ||
| election.election_id, country=country_map[territory_code] | ||
| ) | ||
|
|
||
| # populate the new fields we just added in 0090 and 0091 | ||
| if territory_code == "NIR" or election.election_id.startswith("sp."): | ||
| election.replacement_pack_start_date = None | ||
| else: | ||
| election.replacement_pack_start_date = ( | ||
| timetable.replacement_pack_start_date | ||
| ) | ||
|
|
||
| election.proxy_vote_application_deadline = ( | ||
| timetable.proxy_vote_application_deadline | ||
| ) | ||
|
|
||
| elections_to_update.append(election) | ||
|
|
||
| batch_size = 2000 | ||
| for i in range(0, len(elections_to_update), batch_size): | ||
| qs.bulk_update( | ||
| elections_to_update[i : i + batch_size], | ||
| ["proxy_vote_application_deadline", "replacement_pack_start_date"], | ||
| ) | ||
|
|
||
|
|
||
| def clear_new_timetable_fields(apps, schema_editor): | ||
| Election = apps.get_model("elections", "Election") | ||
| qs = Election.private_objects.using(schema_editor.connection.alias) | ||
|
|
||
| qs.update( | ||
| proxy_vote_application_deadline=None, | ||
| replacement_pack_start_date=None, | ||
| ) | ||
|
|
||
|
|
||
| class Migration(migrations.Migration): | ||
| dependencies = [ | ||
| ("elections", "0092_election_replacement_pack_start_date"), | ||
| ] | ||
|
|
||
| operations = [ | ||
| migrations.RunPython( | ||
| backfill_new_timetable_fields, clear_new_timetable_fields | ||
| ) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the consequences of storing these dates in the DB is: Every time we add a new date or fix a bug, we have to write one of these backfill migrations.