From 8c95e87b0469a48594ddde5ccd8dd937e825ab06 Mon Sep 17 00:00:00 2001 From: gordon pendleton Date: Fri, 24 Jul 2015 14:35:51 -0400 Subject: [PATCH 1/2] fix https://github.com/django/django-formtools/issues/16 --- docs/wizard.rst | 10 ++++++++++ formtools/wizard/views.py | 10 ++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/docs/wizard.rst b/docs/wizard.rst index 78c5bbbe..a918b18a 100644 --- a/docs/wizard.rst +++ b/docs/wizard.rst @@ -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 diff --git a/formtools/wizard/views.py b/formtools/wizard/views.py index aeded43f..e3aa70e7 100644 --- a/formtools/wizard/views.py +++ b/formtools/wizard/views.py @@ -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): @@ -393,6 +393,12 @@ def get_form_kwargs(self, step=None): (or formset) on the given step. """ 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): """ @@ -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({ From ca7c77dd6a587bce631f29667e9e0a9d868c095e Mon Sep 17 00:00:00 2001 From: gordon pendleton Date: Fri, 24 Jul 2015 15:18:24 -0400 Subject: [PATCH 2/2] whitespace --- formtools/wizard/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/formtools/wizard/views.py b/formtools/wizard/views.py index e3aa70e7..9e747b5b 100644 --- a/formtools/wizard/views.py +++ b/formtools/wizard/views.py @@ -393,7 +393,7 @@ def get_form_kwargs(self, step=None): (or formset) on the given step. """ return {} - + def get_form_class(self, step): """ Returns the form class to use for the provided step.