Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Moved the code to handle goto requests in a extra WizardView method.

  • Loading branch information...
commit 46246c66243c97198879c9ac79ef859ae2474524 1 parent 930af66
Stephan Jaekel authored January 30, 2013
28  django/contrib/formtools/wizard/views.py
@@ -257,11 +257,7 @@ def post(self, *args, **kwargs):
257 257
         # form. (This makes stepping back a lot easier).
258 258
         wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
259 259
         if wizard_goto_step and wizard_goto_step in self.get_form_list():
260  
-            self.storage.current_step = wizard_goto_step
261  
-            form = self.get_form(
262  
-                data=self.storage.get_step_data(self.steps.current),
263  
-                files=self.storage.get_step_files(self.steps.current))
264  
-            return self.render(form)
  260
+            return self.render_goto_step(wizard_goto_step)
265 261
 
266 262
         # Check if form was refreshed
267 263
         management_form = ManagementForm(self.request.POST, prefix=self.prefix)
@@ -309,6 +305,17 @@ def render_next_step(self, form, **kwargs):
309 305
         self.storage.current_step = next_step
310 306
         return self.render(new_form, **kwargs)
311 307
 
  308
+    def render_goto_step(self, goto_step, **kwargs):
  309
+        """
  310
+        This method gets called when the current step has to be changed.
  311
+        `goto_step` contains the requested step to go to.
  312
+        """
  313
+        self.storage.current_step = goto_step
  314
+        form = self.get_form(
  315
+            data=self.storage.get_step_data(self.steps.current),
  316
+            files=self.storage.get_step_files(self.steps.current))
  317
+        return self.render(form)
  318
+
312 319
     def render_done(self, form, **kwargs):
313 320
         """
314 321
         This method gets called when all forms passed. The method should also
@@ -652,8 +659,7 @@ def post(self, *args, **kwargs):
652 659
         """
653 660
         wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
654 661
         if wizard_goto_step and wizard_goto_step in self.get_form_list():
655  
-            self.storage.current_step = wizard_goto_step
656  
-            return redirect(self.get_step_url(wizard_goto_step))
  662
+            return self.render_goto_step(wizard_goto_step)
657 663
         return super(NamedUrlWizardView, self).post(*args, **kwargs)
658 664
 
659 665
     def get_context_data(self, form, **kwargs):
@@ -674,6 +680,14 @@ def render_next_step(self, form, **kwargs):
674 680
         self.storage.current_step = next_step
675 681
         return redirect(self.get_step_url(next_step))
676 682
 
  683
+    def render_goto_step(self, goto_step, **kwargs):
  684
+        """
  685
+        This method gets called when the current step has to be changed.
  686
+        `goto_step` contains the requested step to go to.
  687
+        """
  688
+        self.storage.current_step = goto_step
  689
+        return redirect(self.get_step_url(goto_step))
  690
+
677 691
     def render_revalidation_failure(self, failed_step, form, **kwargs):
678 692
         """
679 693
         When a step fails, we have to redirect the user to the first failing
11  docs/ref/contrib/formtools/form-wizard.txt
@@ -454,6 +454,17 @@ Advanced ``WizardView`` methods
454 454
         def process_step_files(self, form):
455 455
             return self.get_form_step_files(form)
456 456
 
  457
+.. method:: WizardView.render_goto_step(step, goto_step, **kwargs)
  458
+
  459
+    .. versionchanged:: 1.6
  460
+
  461
+    This method is called when the step should be changed to something else
  462
+    than the next step. By default, this method just stores the requested
  463
+    step ``goto_step`` in the storage and then renders the new step.
  464
+
  465
+    If you want to store the entered data of the current step before rendering
  466
+    the next step, you can overwrite this method.
  467
+
457 468
 .. method:: WizardView.render_revalidation_failure(step, form, **kwargs)
458 469
 
459 470
     When the wizard thinks all steps have passed it revalidates all forms with

0 notes on commit 46246c6

Please sign in to comment.
Something went wrong with that request. Please try again.