diff --git a/.circleci/config.yml b/.circleci/config.yml index 3b723cc99..ad0f74a70 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -252,14 +252,14 @@ workflows: requires: - "CDK Synth" context: [deployment-development-ee, slack-secrets] - filters: { branches: { only: [ development ] } } + filters: { branches: { only: [ development, "form-tools20251015" ] } } dc-environment: development - code_deploy: name: "Development: AWS CodeDeploy" requires: - "Development: CDK Deploy" context: [deployment-development-ee, slack-secrets] - filters: { branches: { only: [ development ] } } + filters: { branches: { only: [ development, "form-tools20251015" ] } } dc-environment: development - cdk_deploy: name: "Staging: CDK Deploy" diff --git a/every_election/apps/elections/views/id_creator.py b/every_election/apps/elections/views/id_creator.py index 08f0da6cb..90de9f447 100644 --- a/every_election/apps/elections/views/id_creator.py +++ b/every_election/apps/elections/views/id_creator.py @@ -4,7 +4,6 @@ from django import forms from django.db import transaction from django.http import HttpResponseRedirect -from django.utils.functional import cached_property from election_snooper.helpers import post_to_slack from election_snooper.models import SnoopedElection from elections.baker import send_event @@ -122,38 +121,62 @@ def should_show_by_elections_source(wizard): class IDCreatorWizard(NamedUrlSessionWizardView): + def __init__(self, *args, **kwargs): + self.cache = {} + return super().__init__(*args, **kwargs) + def get_template_names(self): return [TEMPLATES[self.steps.current]] - @cached_property + @property def get_election_type(self): - if self.get_cleaned_data_for_step("election_type"): - return self.get_cleaned_data_for_step("election_type").get( - "election_type" - ) - return None + if "election_type" in self.cache: + return self.cache["election_type"] + + cleaned_data = self.get_cleaned_data_for_step("election_type") + if cleaned_data: + self.cache["election_type"] = cleaned_data.get("election_type") + + return self.cache.get("election_type") - @cached_property + @property def get_election_subtypes(self): - if self.get_cleaned_data_for_step("election_subtype"): - return self.get_cleaned_data_for_step("election_subtype").get( + if "election_subtypes" in self.cache: + return self.cache["election_subtypes"] + + if not self.condition_dict["election_subtype"](self): + return None + + cleaned_data = self.get_cleaned_data_for_step("election_subtype") + if cleaned_data: + self.cache["election_subtypes"] = cleaned_data.get( "election_subtype" ) - return None - @cached_property + return self.cache.get("election_subtypes") + + @property def get_organisations(self): - if self.get_cleaned_data_for_step("election_organisation"): - return self.get_cleaned_data_for_step("election_organisation").get( - "election_organisation" - ) if "election_organisation" in self.storage.extra_data: return Organisation.objects.filter( electedrole__election_type__election_type__in=self.storage.extra_data[ "election_organisation" ] ) - return None + + if not self.condition_dict["election_organisation"](self): + return None + + if "organisations" in self.cache: + return self.cache["organisations"] + + cleaned_data = self.get_cleaned_data_for_step("election_organisation") + if cleaned_data: + self.cache["organisations"] = cleaned_data.get( + "election_organisation" + ) + + return self.cache.get("organisations") def get_election_date(self): election_date = self.get_cleaned_data_for_step("date") or {} diff --git a/pyproject.toml b/pyproject.toml index 8e96ef809..8793b793b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,7 +13,7 @@ dependencies = [ "django-cors-headers==4.7.0", "django-extensions==3.2.3", "django-filter==24.3", - "django-formtools==2.3", + "django-formtools==2.5.1", "django-localflavor==4.0", "django-middleware-global-request==0.3.5", "django-model-utils==5.0.0", diff --git a/uv.lock b/uv.lock index 7339aea51..c295509be 100644 --- a/uv.lock +++ b/uv.lock @@ -452,14 +452,14 @@ wheels = [ [[package]] name = "django-formtools" -version = "2.3" +version = "2.5.1" source = { registry = "https://pypi.org/simple" } dependencies = [ { name = "django" }, ] -sdist = { url = "https://files.pythonhosted.org/packages/6e/b0/41ca0a8b7f2ce073f4cfca6adcc7b502a4a894fad9b80505b2ad13dc7aac/django-formtools-2.3.tar.gz", hash = "sha256:9663b6eca64777b68d6d4142efad8597fe9a685924673b25aa8a1dcff4db00c3", size = 83706, upload-time = "2021-04-19T03:58:47.452Z" } +sdist = { url = "https://files.pythonhosted.org/packages/73/f8/bb9b228fc33230186f3612a6fc96274a81bab3509817498f2632d7aa6367/django-formtools-2.5.1.tar.gz", hash = "sha256:47cb34552c6efca088863d693284d04fc36eaaf350eb21e1a1d935e0df523c93", size = 88637, upload-time = "2023-12-19T10:30:59.78Z" } wheels = [ - { url = "https://files.pythonhosted.org/packages/8e/dd/0bce8b9cc6dfa80a4c510e625f54be4348e799d9c594f98c1cd83e63cd2a/django_formtools-2.3-py3-none-any.whl", hash = "sha256:4699937e19ee041d803943714fe0c1c7ad4cab802600eb64bbf4cdd0a1bfe7d9", size = 148867, upload-time = "2021-04-19T03:58:32.131Z" }, + { url = "https://files.pythonhosted.org/packages/12/63/91a107e3aaaf3987bad036494dfd8cc2675f4a66d22e65ffd6711f84ba70/django_formtools-2.5.1-py3-none-any.whl", hash = "sha256:bce9b64eda52cc1eef6961cc649cf75aacd1a707c2fff08d6c3efcbc8e7e761a", size = 170651, upload-time = "2023-12-19T10:30:02.816Z" }, ] [[package]] @@ -667,7 +667,7 @@ requires-dist = [ { name = "django-cors-headers", specifier = "==4.7.0" }, { name = "django-extensions", specifier = "==3.2.3" }, { name = "django-filter", specifier = "==24.3" }, - { name = "django-formtools", specifier = "==2.3" }, + { name = "django-formtools", specifier = "==2.5.1" }, { name = "django-localflavor", specifier = "==4.0" }, { name = "django-middleware-global-request", specifier = "==0.3.5" }, { name = "django-model-utils", specifier = "==5.0.0" },