From 75dc7eafc2d54fb9c582e03595c4a84765c06933 Mon Sep 17 00:00:00 2001 From: Todd Dembrey <todd.dembrey@torchbox.com> Date: Wed, 24 Jan 2018 14:11:38 +0000 Subject: [PATCH] Map the cleaned data back from ids for access from the json field --- opentech/apply/funds/models.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 528c72e50..5bde11f20 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -24,7 +24,7 @@ from wagtail.wagtailforms.models import AbstractFormSubmission from opentech.apply.stream_forms.models import AbstractStreamForm -from .blocks import CustomFormFieldsBlock, REQUIRED_BLOCK_NAMES +from .blocks import CustomFormFieldsBlock, MustIncludeFieldBlock, REQUIRED_BLOCK_NAMES from .forms import WorkflowFormAdminForm from .workflow import SingleStage, DoubleStage @@ -60,9 +60,15 @@ class FundType(AbstractStreamForm): return ApplicationSubmission def process_form_submission(self, form): - # Handle passing to JSONField + cleaned_data = form.cleaned_data + for field in self.get_defined_fields(): + # Update the ids which are unique to use the unique name + if isinstance(field.block, MustIncludeFieldBlock): + response = cleaned_data.pop(field.id) + cleaned_data[field.block.name] = response + return self.get_submission_class().objects.create( - form_data=form.cleaned_data, + form_data=cleaned_data, page=self, ) -- GitLab