Skip to content

Commit

Permalink
Add expected_sopn_date for ballots
Browse files Browse the repository at this point in the history
  • Loading branch information
VirginiaDooley committed Sep 20, 2023
1 parent 9aa5033 commit aa83d6a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ djangorestframework-jsonp==1.0.2
djangorestframework-csv==2.1.1
djangorestframework==3.14
drf-yasg==1.21.5
uk-election-timetables==2.4.1
factory-boy==3.2.1
Faker==19.2.0
freezegun==1.2.2
Expand Down
20 changes: 20 additions & 0 deletions ynr/apps/candidates/helpers/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from uk_election_timetables.calendars import Country
from uk_election_timetables.election_ids import from_election_id


def get_election_timetable(slug, territory):
country = {
"ENG": Country.ENGLAND,
"WLS": Country.WALES,
"SCT": Country.SCOTLAND,
"NIR": Country.NORTHERN_IRELAND,
}

if slug.startswith("local") and territory not in country:
return None

try:
return from_election_id(slug, country[territory])

except BaseException:
return None
11 changes: 11 additions & 0 deletions ynr/apps/candidates/models/popolo_extra.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import datetime
import hashlib

from candidates.helpers.helpers import get_election_timetable
from candidates.models import LoggedAction
from candidates.models.auth import TRUSTED_TO_LOCK_GROUP_NAME
from candidates.models.db import ActionType
Expand Down Expand Up @@ -558,6 +559,16 @@ def is_welsh_run(self):

return self.tags.get("NUTS1", {}).get("key") == "UKL"

@property
def expected_sopn_date(self):
try:
return get_election_timetable(
self.ballot_paper_id, self.post.territory_code
).sopn_publish_date

except AttributeError:
return None


class PartySet(models.Model):
slug = models.CharField(max_length=256, unique=True)
Expand Down

0 comments on commit aa83d6a

Please sign in to comment.