Skip to content
Snippets Groups Projects
Commit 3614211c authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Ensure that the form objects is cloned on creation of a round

debug actual behaviour

squash! debug actual behaviour
parent 1664f520
No related branches found
No related tags found
No related merge requests found
......@@ -236,17 +236,23 @@ class Round(SubmittableStreamForm):
FieldPanel('start_date'),
FieldPanel('end_date'),
]),
], heading="Dates")
], heading="Dates"),
]
def save(self, *args, **kwargs):
def create(self, *args, **kwargs):
if hasattr(self, 'parent_page'):
# We attached the parent page as part of the before_create_hook
self.workflow = self.parent_page.workflow
for form in self.parent_page.forms.all():
RoundForm.objects.create(round=self, form=form.form)
super().save(*args, **kwargs)
if hasattr(self, 'parent_page'):
for form in self.parent_page.forms.all():
# Create a copy of the existing form object
new_form = form.form
new_form.id = None
new_form.save()
RoundForm.objects.create(round=self, form=new_form)
def get_submit_meta_data(self, **kwargs):
return super().get_submit_meta_data(
......
......@@ -4,7 +4,7 @@ from opentech.apply.stream_forms.blocks import FormFieldBlock
from opentech.apply.funds import blocks
__all__ = ['FormFieldBlock', 'FullNameBlockFactory', 'EmailBlockFactory']
__all__ = ['CustomFormFieldsFactory', 'FormFieldBlock', 'FullNameBlockFactory', 'EmailBlockFactory']
class FormFieldBlockFactory(wagtail_factories.StructBlockFactory):
......@@ -20,3 +20,9 @@ class EmailBlockFactory(FormFieldBlockFactory):
class FullNameBlockFactory(FormFieldBlockFactory):
class Meta:
model = blocks.FullNameBlock
CustomFormFieldsFactory = wagtail_factories.StreamFieldFactory({
'email': EmailBlockFactory,
'full_name': FullNameBlockFactory,
})
......@@ -149,8 +149,17 @@ class FundTypeFactory(wagtail_factories.PageFactory):
@factory.post_generation
def forms(self, create, extracted, **kwargs):
if create:
fields = {
f'form__form_fields__{i}__{field}__': ''
for i, field in enumerate(blocks.CustomFormFieldsFactory.factories.keys())
}
fields.update(**kwargs)
for _ in range(len(self.workflow_class.stage_classes)):
FundFormFactory(fund=self)
# Generate a form based on all defined fields on the model
FundFormFactory(
fund=self,
**fields,
)
class FundFormFactory(factory.DjangoModelFactory):
......@@ -165,11 +174,7 @@ class ApplicationFormFactory(factory.DjangoModelFactory):
model = ApplicationForm
name = factory.Faker('word')
form_fields = wagtail_factories.StreamFieldFactory({
'email': blocks.EmailBlockFactory,
'full_name': blocks.FullNameBlockFactory,
})
form_fields = blocks.CustomFormFieldsFactory
class RoundFactory(wagtail_factories.PageFactory):
class Meta:
......
......@@ -14,6 +14,7 @@ from opentech.apply.funds.workflow import SingleStage
from .factories import (
ApplicationFormFactory,
CustomFormFieldsFactory,
FundFormFactory,
FundTypeFactory,
LabFactory,
......@@ -160,7 +161,13 @@ class TestRoundModelWorkflowAndForms(TestCase):
self.round.save()
# We are no longer creating a round
del self.round.parent_page
form = self.round.forms.first()
form = self.round.forms.first().form
# Not ideal, would prefer better way to create the stream values
new_field = CustomFormFieldsFactory.generate(None, {'0__email__': ''})
form.form_fields = new_field
form.save()
for round_form, fund_form in itertools.zip_longest(self.round.forms.all(), self.fund.forms.all()):
self.assertNotEqual(round_form, fund_form)
class TestFormSubmission(TestCase):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment