diff options
| author | Julian Wachholz <julian@wachholz.ch> | 2014-02-09 16:44:31 +0000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2014-02-10 07:28:39 -0500 |
| commit | 9a4ee8ddb858ae07ff42be0261c867aa3d2eb53c (patch) | |
| tree | 2d875068e16701a8be91f00e11578f781977c62b /django | |
| parent | b102c27ff4d21ea6262e600227530f75337a5df2 (diff) | |
Fixed #21994 -- Added form_dict argument to calls of WizardView.done()
Added an additional keyword argument ``form_dict`` to calls of
WizardView.done() implementations which allows easier access to validated
forms by their step name.
Diffstat (limited to 'django')
3 files changed, 9 insertions, 3 deletions
diff --git a/django/contrib/formtools/tests/wizard/namedwizardtests/forms.py b/django/contrib/formtools/tests/wizard/namedwizardtests/forms.py index fa9071d9db..6e38a8a739 100644 --- a/django/contrib/formtools/tests/wizard/namedwizardtests/forms.py +++ b/django/contrib/formtools/tests/wizard/namedwizardtests/forms.py @@ -39,6 +39,7 @@ class ContactWizard(NamedUrlWizardView): def done(self, form_list, **kwargs): c = Context({ 'form_list': [x.cleaned_data for x in form_list], + 'form_dict': kwargs.get('form_dict'), 'all_cleaned_data': self.get_all_cleaned_data() }) diff --git a/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py b/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py index b6125db5b9..6e22549007 100644 --- a/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py +++ b/django/contrib/formtools/tests/wizard/namedwizardtests/tests.py @@ -219,6 +219,11 @@ class NamedWizardTests(object): {'random_crap': 'blah blah'} ]}) + form_dict = response.context['form_dict'] + self.assertIn('form1', form_dict.keys()) + self.assertIn('form2', form_dict.keys()) + self.assertEqual(form_dict['form1'].cleaned_data, response.context['form_list'][0]) + def test_manipulated_data(self): response = self.client.get( reverse(self.wizard_urlname, kwargs={'step': 'form1'})) diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py index 2b4a86d115..f5cf563ad5 100644 --- a/django/contrib/formtools/wizard/views.py +++ b/django/contrib/formtools/wizard/views.py @@ -335,7 +335,7 @@ class WizardView(TemplateView): validate, `render_revalidation_failure` should get called. If everything is fine call `done`. """ - final_form_list = [] + final_forms = OrderedDict() # walk through the form list and try to validate the data again. for form_key in self.get_form_list(): form_obj = self.get_form(step=form_key, @@ -343,12 +343,12 @@ class WizardView(TemplateView): files=self.storage.get_step_files(form_key)) if not form_obj.is_valid(): return self.render_revalidation_failure(form_key, form_obj, **kwargs) - final_form_list.append(form_obj) + final_forms[form_key] = form_obj # render the done view and reset the wizard before returning the # response. This is needed to prevent from rendering done with the # same data twice. - done_response = self.done(final_form_list, **kwargs) + done_response = self.done(final_forms.values(), form_dict=final_forms, **kwargs) self.storage.reset() return done_response |
