Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix https://github.com/django/django-formtools/issues/16 #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/wizard.rst
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ Advanced ``WizardView`` methods
def get_form_kwargs(self, step):
return {}

.. method:: WizardView.get_form_class(step)

Returns the form class which will be used when instantiating the form
instance on given ``step``.

The default implementation::

def get_form_class(self, step):
return self.form_list[step]

.. method:: WizardView.get_form_instance(step)

This method will be called only if a :class:`~django.forms.ModelForm` is
Expand Down
10 changes: 8 additions & 2 deletions formtools/wizard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def get_form_list(self):
# call the value if needed, passes the current instance.
condition = condition(self)
if condition:
form_list[form_key] = form_class
form_list[form_key] = self.get_form_class(form_key)
return form_list

def dispatch(self, request, *args, **kwargs):
Expand Down Expand Up @@ -394,6 +394,12 @@ def get_form_kwargs(self, step=None):
"""
return {}

def get_form_class(self, step):
"""
Returns the form class to use for the provided step.
"""
return self.form_list[step]

def get_form(self, step=None, data=None, files=None):
"""
Constructs the form for a given `step`. If no `step` is defined, the
Expand All @@ -405,7 +411,7 @@ def get_form(self, step=None, data=None, files=None):
"""
if step is None:
step = self.steps.current
form_class = self.form_list[step]
form_class = self.get_form_class(step)
# prepare the kwargs for the form instance.
kwargs = self.get_form_kwargs(step)
kwargs.update({
Expand Down