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

@ -114,11 +114,11 @@ anywhere in your codebase, but convention is to put it in :file:`views.py`.
The only requirement on this subclass is that it implement a
:meth:`~WizardView.done()` method.
.. method:: WizardView.done(form_list)
.. method:: WizardView.done(form_list, form_dict, **kwargs)
This method specifies what should happen when the data for *every* form is
submitted and validated. This method is passed a list of validated
:class:`~django.forms.Form` instances.
submitted and validated. This method is passed a list and dictionary of
validated :class:`~django.forms.Form` instances.
In this simplistic example, rather than performing any database operation,
the method simply renders a template of the validated data::
@ -144,6 +144,21 @@ The only requirement on this subclass is that it implement a
do_something_with_the_form_data(form_list)
return HttpResponseRedirect('/page-to-redirect-to-when-done/')
In addition to ``form_list``, the :meth:`~WizardView.done` method
is passed a ``form_dict``, which allows you to access the wizard's
forms based on their step names. This is especially useful when using
:class:`NamedUrlWizardView`, for example::
def done(self, form_list, form_dict, **kwargs):
user = form_dict['user'].save()
credit_card = form_dict['credit_card'].save()
# ...
.. versionchanged:: 1.7
Previously, the ``form_dict`` argument wasn't passed to the
``done`` method.
See the section :ref:`Advanced WizardView methods <wizardview-advanced-methods>`
below to learn about more :class:`WizardView` hooks.