Code

Ticket #17162: 17162.diff

File 17162.diff, 3.2 KB (added by Bradley Ayers <bradley.ayers@…>, 2 years ago)
Line 
1Index: docs/ref/contrib/formtools/form-wizard.txt
2===================================================================
3--- docs/ref/contrib/formtools/form-wizard.txt  (revision 17068)
4+++ docs/ref/contrib/formtools/form-wizard.txt  (working copy)
5@@ -318,19 +318,21 @@
6         def get_wizard_name(self):
7             return normalize_name(self.__class__.__name__)
8 
9-.. method:: WizardView.get_prefix()
10+.. method:: WizardView.get_prefix(request, *args, **kwargs)
11 
12-    This method returns a prefix for the storage backends. These backends use
13-    the prefix to fetch the correct data for the wizard. (Multiple wizards
14-    could save their data in one session)
15+    This method returns a prefix for use by the storage backends. Backends use
16+    the prefix as a mechanism to allow data to be stored separately for each
17+    wizard. This allows wizards to store their data in a single backend
18+    without overwriting each other.
19 
20     You can change this method to make the wizard data prefix more unique to,
21     e.g. have multiple instances of one wizard in one session.
22 
23     Default implementation::
24 
25-        def get_prefix(self):
26-            return self.wizard_name
27+        def get_prefix(self, request, *args, **kwargs):
28+            # use the lowercase underscore version of the class name
29+            return normalize_name(self.__class__.__name__)
30 
31 .. method:: WizardView.get_form(step=None, data=None, files=None)
32 
33Index: django/contrib/formtools/wizard/views.py
34===================================================================
35--- django/contrib/formtools/wizard/views.py    (revision 17068)
36+++ django/contrib/formtools/wizard/views.py    (working copy)
37@@ -14,6 +14,15 @@
38 
39 
40 def normalize_name(name):
41+    """
42+    Converts camel-case style names into underscore seperated words. Example::
43+
44+        >>> normalize_name('oneTwoThree')
45+        'one_two_three'
46+        >>> normalize_name('FourFiveSix')
47+        'four_five_six'
48+
49+    """
50     new = re.sub('(((?<=[a-z])[A-Z])|([A-Z](?![A-Z]|$)))', '_\\1', name)
51     return new.lower().strip('_')
52 
53@@ -169,13 +178,10 @@
54         kwargs['form_list'] = init_form_list
55         return kwargs
56 
57-    def get_wizard_name(self):
58+    def get_prefix(self, request, *args, **kwargs):
59+        # TODO: Add some kind of unique id to prefix
60         return normalize_name(self.__class__.__name__)
61 
62-    def get_prefix(self):
63-        # TODO: Add some kind of unique id to prefix
64-        return self.wizard_name
65-
66     def get_form_list(self):
67         """
68         This method returns a form_list based on the initial form list but
69@@ -210,8 +216,7 @@
70         response gets updated by the storage engine (for example add cookies).
71         """
72         # add the storage engine to the current formwizard instance
73-        self.wizard_name = self.get_wizard_name()
74-        self.prefix = self.get_prefix()
75+        self.prefix = self.get_prefix(request, *args, **kwargs)
76         self.storage = get_storage(self.storage_name, self.prefix, request,
77             getattr(self, 'file_storage', None))
78         self.steps = StepsHelper(self)
79@@ -683,4 +688,3 @@
80     A NamedUrlFormWizard with pre-configured CookieStorageBackend.
81     """
82     storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'
83-