Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #942 from stephrdev/trac-18000

Fixed #18000 -- Moved the code to handle goto requests to an extra WizardView method.
  • Loading branch information...
commit e7514e4978178ba68a872ac0004dd6f8049f3d76 2 parents f2c55d2 + 1c8a170
Jannis Leidel authored March 23, 2013
28  django/contrib/formtools/wizard/views.py
@@ -265,11 +265,7 @@ def post(self, *args, **kwargs):
265 265
         # form. (This makes stepping back a lot easier).
266 266
         wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
267 267
         if wizard_goto_step and wizard_goto_step in self.get_form_list():
268  
-            self.storage.current_step = wizard_goto_step
269  
-            form = self.get_form(
270  
-                data=self.storage.get_step_data(self.steps.current),
271  
-                files=self.storage.get_step_files(self.steps.current))
272  
-            return self.render(form)
  268
+            return self.render_goto_step(wizard_goto_step)
273 269
 
274 270
         # Check if form was refreshed
275 271
         management_form = ManagementForm(self.request.POST, prefix=self.prefix)
@@ -317,6 +313,17 @@ def render_next_step(self, form, **kwargs):
317 313
         self.storage.current_step = next_step
318 314
         return self.render(new_form, **kwargs)
319 315
 
  316
+    def render_goto_step(self, goto_step, **kwargs):
  317
+        """
  318
+        This method gets called when the current step has to be changed.
  319
+        `goto_step` contains the requested step to go to.
  320
+        """
  321
+        self.storage.current_step = goto_step
  322
+        form = self.get_form(
  323
+            data=self.storage.get_step_data(self.steps.current),
  324
+            files=self.storage.get_step_files(self.steps.current))
  325
+        return self.render(form)
  326
+
320 327
     def render_done(self, form, **kwargs):
321 328
         """
322 329
         This method gets called when all forms passed. The method should also
@@ -660,8 +667,7 @@ def post(self, *args, **kwargs):
660 667
         """
661 668
         wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
662 669
         if wizard_goto_step and wizard_goto_step in self.get_form_list():
663  
-            self.storage.current_step = wizard_goto_step
664  
-            return redirect(self.get_step_url(wizard_goto_step))
  670
+            return self.render_goto_step(wizard_goto_step)
665 671
         return super(NamedUrlWizardView, self).post(*args, **kwargs)
666 672
 
667 673
     def get_context_data(self, form, **kwargs):
@@ -682,6 +688,14 @@ def render_next_step(self, form, **kwargs):
682 688
         self.storage.current_step = next_step
683 689
         return redirect(self.get_step_url(next_step))
684 690
 
  691
+    def render_goto_step(self, goto_step, **kwargs):
  692
+        """
  693
+        This method gets called when the current step has to be changed.
  694
+        `goto_step` contains the requested step to go to.
  695
+        """
  696
+        self.storage.current_step = goto_step
  697
+        return redirect(self.get_step_url(goto_step))
  698
+
685 699
     def render_revalidation_failure(self, failed_step, form, **kwargs):
686 700
         """
687 701
         When a step fails, we have to redirect the user to the first failing
11  docs/ref/contrib/formtools/form-wizard.txt
@@ -469,6 +469,17 @@ Advanced ``WizardView`` methods
469 469
         def process_step_files(self, form):
470 470
             return self.get_form_step_files(form)
471 471
 
  472
+.. method:: WizardView.render_goto_step(step, goto_step, **kwargs)
  473
+
  474
+    .. versionadded:: 1.6
  475
+
  476
+    This method is called when the step should be changed to something else
  477
+    than the next step. By default, this method just stores the requested
  478
+    step ``goto_step`` in the storage and then renders the new step.
  479
+
  480
+    If you want to store the entered data of the current step before rendering
  481
+    the next step, you can overwrite this method.
  482
+
472 483
 .. method:: WizardView.render_revalidation_failure(step, form, **kwargs)
473 484
 
474 485
     When the wizard thinks all steps have passed it revalidates all forms with

0 notes on commit e7514e4

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