diff --git a/django/contrib/formtools/wizard/views.py b/django/contrib/formtools/wizard/views.py index ac902edbef..c5fab17f07 100644 --- a/django/contrib/formtools/wizard/views.py +++ b/django/contrib/formtools/wizard/views.py @@ -14,6 +14,15 @@ from django.contrib.formtools.wizard.forms import ManagementForm def normalize_name(name): + """ + Converts camel-case style names into underscore seperated words. Example:: + + >>> normalize_name('oneTwoThree') + 'one_two_three' + >>> normalize_name('FourFiveSix') + 'four_five_six' + + """ new = re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', '_\\1', name) return new.lower().strip('_') @@ -169,12 +178,9 @@ class WizardView(TemplateView): kwargs['form_list'] = init_form_list return kwargs - def get_wizard_name(self): - return normalize_name(self.__class__.__name__) - - def get_prefix(self): + def get_prefix(self, *args, **kwargs): # TODO: Add some kind of unique id to prefix - return self.wizard_name + return normalize_name(self.__class__.__name__) def get_form_list(self): """ @@ -210,8 +216,7 @@ class WizardView(TemplateView): response gets updated by the storage engine (for example add cookies). """ # add the storage engine to the current formwizard instance - self.wizard_name = self.get_wizard_name() - self.prefix = self.get_prefix() + self.prefix = self.get_prefix(*args, **kwargs) self.storage = get_storage(self.storage_name, self.prefix, request, getattr(self, 'file_storage', None)) self.steps = StepsHelper(self) diff --git a/docs/ref/contrib/formtools/form-wizard.txt b/docs/ref/contrib/formtools/form-wizard.txt index 01f5567706..58cb0e28d2 100644 --- a/docs/ref/contrib/formtools/form-wizard.txt +++ b/docs/ref/contrib/formtools/form-wizard.txt @@ -314,28 +314,21 @@ Advanced ``WizardView`` methods context.update({'another_var': True}) return context -.. method:: WizardView.get_wizard_name() +.. method:: WizardView.get_prefix(*args, **kwargs) - This method can be used to change the wizard's internal name. - - Default implementation:: - - def get_wizard_name(self): - return normalize_name(self.__class__.__name__) - -.. method:: WizardView.get_prefix() - - This method returns a prefix for the storage backends. These backends use - the prefix to fetch the correct data for the wizard. (Multiple wizards - could save their data in one session) + This method returns a prefix for use by the storage backends. Backends use + the prefix as a mechanism to allow data to be stored separately for each + wizard. This allows wizards to store their data in a single backend + without overwriting each other. You can change this method to make the wizard data prefix more unique to, e.g. have multiple instances of one wizard in one session. Default implementation:: - def get_prefix(self): - return self.wizard_name + def get_prefix(self, *args, **kwargs): + # use the lowercase underscore version of the class name + return normalize_name(self.__class__.__name__) .. method:: WizardView.get_form(step=None, data=None, files=None)