Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17163 -- Added the `NamedUrlWizardView.get_step_url()` method.…

… Thanks, Bradley Ayers.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17235 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 355f7fc564cb4dc67a84075664bf98ac203d2b13 1 parent 1ef6841
Julien Phalip authored December 19, 2011
19  django/contrib/formtools/wizard/views.py
@@ -591,6 +591,9 @@ def get_initkwargs(cls, *args, **kwargs):
591 591
             'step name "%s" is reserved for "done" view' % initkwargs['done_step_name']
592 592
         return initkwargs
593 593
 
  594
+    def get_step_url(self, step):
  595
+        return reverse(self.url_name, kwargs={'step': step})
  596
+
594 597
     def get(self, *args, **kwargs):
595 598
         """
596 599
         This renders the form or, if needed, does the http redirects.
@@ -604,10 +607,8 @@ def get(self, *args, **kwargs):
604 607
                 query_string = "?%s" % self.request.GET.urlencode()
605 608
             else:
606 609
                 query_string = ""
607  
-            next_step_url = reverse(self.url_name, kwargs={
608  
-                'step': self.steps.current,
609  
-            }) + query_string
610  
-            return redirect(next_step_url)
  610
+            return redirect(self.get_step_url(self.steps.current)
  611
+                            + query_string)
611 612
 
612 613
         # is the current step the "done" name/view?
613 614
         elif step_url == self.done_step_name:
@@ -636,7 +637,7 @@ def get(self, *args, **kwargs):
636 637
         # invalid step name, reset to first and redirect.
637 638
         else:
638 639
             self.storage.current_step = self.steps.first
639  
-            return redirect(self.url_name, step=self.steps.first)
  640
+            return redirect(self.get_step_url(self.steps.first))
640 641
 
641 642
     def post(self, *args, **kwargs):
642 643
         """
@@ -646,7 +647,7 @@ def post(self, *args, **kwargs):
646 647
         wizard_goto_step = self.request.POST.get('wizard_goto_step', None)
647 648
         if wizard_goto_step and wizard_goto_step in self.get_form_list():
648 649
             self.storage.current_step = wizard_goto_step
649  
-            return redirect(self.url_name, step=wizard_goto_step)
  650
+            return redirect(self.get_step_url(wizard_goto_step))
650 651
         return super(NamedUrlWizardView, self).post(*args, **kwargs)
651 652
 
652 653
     def get_context_data(self, form, **kwargs):
@@ -665,7 +666,7 @@ def render_next_step(self, form, **kwargs):
665 666
         """
666 667
         next_step = self.get_next_step()
667 668
         self.storage.current_step = next_step
668  
-        return redirect(self.url_name, step=next_step)
  669
+        return redirect(self.get_step_url(next_step))
669 670
 
670 671
     def render_revalidation_failure(self, failed_step, form, **kwargs):
671 672
         """
@@ -673,7 +674,7 @@ def render_revalidation_failure(self, failed_step, form, **kwargs):
673 674
         step.
674 675
         """
675 676
         self.storage.current_step = failed_step
676  
-        return redirect(self.url_name, step=failed_step)
  677
+        return redirect(self.get_step_url(failed_step))
677 678
 
678 679
     def render_done(self, form, **kwargs):
679 680
         """
@@ -681,7 +682,7 @@ def render_done(self, form, **kwargs):
681 682
         name doesn't fit).
682 683
         """
683 684
         if kwargs.get('step', None) != self.done_step_name:
684  
-            return redirect(self.url_name, step=self.done_step_name)
  685
+            return redirect(self.get_step_url(self.done_step_name))
685 686
         return super(NamedUrlWizardView, self).render_done(form, **kwargs)
686 687
 
687 688
 
16  docs/ref/contrib/formtools/form-wizard.txt
@@ -557,8 +557,8 @@ an ``instance_dict`` argument that should contain instances of ``ModelForm`` and
557 557
 ``ModelFormSet``.  Similarly to :attr:`~WizardView.initial_dict`, these
558 558
 dictionary key values should be equal to the step number in the form list.
559 559
 
560  
-Usage of NamedUrlWizardView
561  
-===========================
  560
+Usage of ``NamedUrlWizardView``
  561
+===============================
562 562
 
563 563
 .. class:: NamedUrlWizardView
564 564
 
@@ -595,3 +595,15 @@ Example code for the changed ``urls.py`` file::
595 595
         url(r'^contact/(?P<step>.+)/$', contact_wizard, name='contact_step'),
596 596
         url(r'^contact/$', contact_wizard, name='contact'),
597 597
     )
  598
+
  599
+Advanced ``NamedUrlWizardView`` methods
  600
+=======================================
  601
+
  602
+.. method:: NamedUrlWizardView.get_step_url(step)
  603
+
  604
+    This method returns the URL for a specific step.
  605
+
  606
+    Default implementation::
  607
+
  608
+        def get_step_url(self, step):
  609
+            return reverse(self.url_name, kwargs={'step': step})

0 notes on commit 355f7fc

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