Code

Ticket #18000: wizard_save_goto_step.diff

File wizard_save_goto_step.diff, 2.8 KB (added by creecode, 2 years ago)
Line 
1Index: django/contrib/formtools/wizard/views.py
2===================================================================
3--- django/contrib/formtools/wizard/views.py    (revision 17813)
4+++ django/contrib/formtools/wizard/views.py    (working copy)
5@@ -246,18 +246,16 @@
6 
7         The wizard will render either the current step (if form validation
8         wasn't successful), the next step (if the current step was stored
9-        successful) or the done view (if no more steps are available)
10+        successfully) or the done view (if no more steps are available)
11         """
12         # Look for a wizard_goto_step element in the posted data which
13         # contains a valid step name. If one was found, render the requested
14         # form. (This makes stepping back a lot easier).
15-        wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
16-        if wizard_goto_step and wizard_goto_step in self.get_form_list():
17-            self.storage.current_step = wizard_goto_step
18-            form = self.get_form(
19-                data=self.storage.get_step_data(self.steps.current),
20-                files=self.storage.get_step_files(self.steps.current))
21-            return self.render(form)
22+        wizard_cancel_step_goto = self.request.POST.get(
23+            'wizard_cancel_step_goto', None)
24+        if wizard_cancel_step_goto and wizard_cancel_step_goto in \
25+            self.get_form_list():
26+            return self.render_step(wizard_cancel_step_goto)
27 
28         # Check if form was refreshed
29         management_form = ManagementForm(self.request.POST, prefix=self.prefix)
30@@ -280,6 +278,11 @@
31             self.storage.set_step_data(self.steps.current, self.process_step(form))
32             self.storage.set_step_files(self.steps.current, self.process_step_files(form))
33 
34+            # check if this is a goto step
35+            wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
36+            if wizard_goto_step and wizard_goto_step in self.get_form_list():
37+                return self.render_step(wizard_goto_step)
38+
39             # check if the current step is the last step
40             if self.steps.current == self.steps.last:
41                 # no more steps, render done view
42@@ -553,7 +556,17 @@
43         raise NotImplementedError("Your %s class has not defined a done() "
44             "method, which is required." % self.__class__.__name__)
45 
46+    def render_step ( self, step ):
47+        """
48+        This method is used to render a given step. `step` contains the step-name.
49+        """
50+        self.storage.current_step = step
51+        form = self.get_form(
52+            data=self.storage.get_step_data(self.steps.current),
53+            files=self.storage.get_step_files(self.steps.current))
54+        return self.render(form)
55 
56+
57 class SessionWizardView(WizardView):
58     """
59     A WizardView with pre-configured SessionStorage backend.