1
0
mirror of https://github.com/django/django.git synced 2025-10-24 14:16:09 +00:00

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.
This commit is contained in:
Julian Wachholz
2014-02-09 16:44:31 +00:00
committed by Tim Graham
parent b102c27ff4
commit 9a4ee8ddb8
5 changed files with 34 additions and 6 deletions

View File

@@ -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()
})

View File

@@ -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'}))

View File

@@ -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