Ticket #17162: 17162.diff
File 17162.diff, 3.2 KB (added by , 13 years ago) |
---|
-
docs/ref/contrib/formtools/form-wizard.txt
318 318 def get_wizard_name(self): 319 319 return normalize_name(self.__class__.__name__) 320 320 321 .. method:: WizardView.get_prefix( )321 .. method:: WizardView.get_prefix(request, *args, **kwargs) 322 322 323 This method returns a prefix for the storage backends. These backends use 324 the prefix to fetch the correct data for the wizard. (Multiple wizards 325 could save their data in one session) 323 This method returns a prefix for use by the storage backends. Backends use 324 the prefix as a mechanism to allow data to be stored separately for each 325 wizard. This allows wizards to store their data in a single backend 326 without overwriting each other. 326 327 327 328 You can change this method to make the wizard data prefix more unique to, 328 329 e.g. have multiple instances of one wizard in one session. 329 330 330 331 Default implementation:: 331 332 332 def get_prefix(self): 333 return self.wizard_name 333 def get_prefix(self, request, *args, **kwargs): 334 # use the lowercase underscore version of the class name 335 return normalize_name(self.__class__.__name__) 334 336 335 337 .. method:: WizardView.get_form(step=None, data=None, files=None) 336 338 -
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