Skip to content

Commit

Permalink
Fixed #17162 -- Removed the useless WizardView.get_wizard_name() me…
Browse files Browse the repository at this point in the history
…thod. Thanks, Bradley Ayers and Stephan Jaekel.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17234 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
jphalip committed Dec 19, 2011
1 parent ed56e2c commit 1ef6841
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
19 changes: 12 additions & 7 deletions django/contrib/formtools/wizard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@


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('_')

Expand Down Expand Up @@ -169,12 +178,9 @@ def get_initkwargs(cls, form_list, initial_dict=None,
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):
"""
Expand Down Expand Up @@ -210,8 +216,7 @@ def dispatch(self, request, *args, **kwargs):
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)
Expand Down
23 changes: 8 additions & 15 deletions docs/ref/contrib/formtools/form-wizard.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 1ef6841

Please sign in to comment.