Ticket #17162: 17162-2.diff
File 17162-2.diff, 3.4 KB (added by , 13 years ago) |
---|
-
docs/ref/contrib/formtools/form-wizard.txt
309 309 context.update({'another_var': True}) 310 310 return context 311 311 312 .. method:: WizardView.get_ wizard_name()312 .. method:: WizardView.get_prefix(request, *args, **kwargs) 313 313 314 This method can be used to change the wizard's internal name. 314 This method returns a prefix for use by the storage backends. Backends use 315 the prefix as a mechanism to allow data to be stored separately for each 316 wizard. This allows wizards to store their data in a single backend 317 without overwriting each other. 315 318 316 Default implementation::317 318 def get_wizard_name(self):319 return normalize_name(self.__class__.__name__)320 321 .. method:: WizardView.get_prefix()322 323 This method returns a prefix for the storage backends. These backends use324 the prefix to fetch the correct data for the wizard. (Multiple wizards325 could save their data in one session)326 327 319 You can change this method to make the wizard data prefix more unique to, 328 320 e.g. have multiple instances of one wizard in one session. 329 321 330 322 Default implementation:: 331 323 332 def get_prefix(self): 333 return self.wizard_name 324 def get_prefix(self, request, *args, **kwargs): 325 # use the lowercase underscore version of the class name 326 return normalize_name(self.__class__.__name__) 334 327 335 328 .. method:: WizardView.get_form(step=None, data=None, files=None) 336 329 -
django/contrib/formtools/wizard/views.py
14 14 15 15 16 16 def normalize_name(name): 17 """ 18 Converts camel-case style names into underscore seperated words. Example:: 19 20 >>> normalize_name('oneTwoThree') 21 'one_two_three' 22 >>> normalize_name('FourFiveSix') 23 'four_five_six' 24 25 """ 17 26 new = re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', '_\\1', name) 18 27 return new.lower().strip('_') 19 28 … … 169 178 kwargs['form_list'] = init_form_list 170 179 return kwargs 171 180 172 def get_wizard_name(self): 181 def get_prefix(self, request, *args, **kwargs): 182 # TODO: Add some kind of unique id to prefix 173 183 return normalize_name(self.__class__.__name__) 174 184 175 def get_prefix(self):176 # TODO: Add some kind of unique id to prefix177 return self.wizard_name178 179 185 def get_form_list(self): 180 186 """ 181 187 This method returns a form_list based on the initial form list but … … 210 216 response gets updated by the storage engine (for example add cookies). 211 217 """ 212 218 # add the storage engine to the current formwizard instance 213 self.wizard_name = self.get_wizard_name() 214 self.prefix = self.get_prefix() 219 self.prefix = self.get_prefix(request, *args, **kwargs) 215 220 self.storage = get_storage(self.storage_name, self.prefix, request, 216 221 getattr(self, 'file_storage', None)) 217 222 self.steps = StepsHelper(self) … … 683 688 A NamedUrlFormWizard with pre-configured CookieStorageBackend. 684 689 """ 685 690 storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage' 686