Ticket #17163: 17163.diff

File 17163.diff, 4.0 KB (added by Bradley Ayers <bradley.ayers@…>, 13 years ago)
  • docs/ref/contrib/formtools/form-wizard.txt

     
    559559``ModelFormSet``.  Similarly to :attr:`~WizardView.initial_dict`, these
    560560dictionary key values should be equal to the step number in the form list.
    561561
    562 Usage of NamedUrlWizardView
    563 ===========================
     562Usage of ``NamedUrlWizardView``
     563===============================
    564564
    565565.. class:: NamedUrlWizardView
    566566
     
    597597        url(r'^contact/(?P<step>.+)/$', contact_wizard, name='contact_step'),
    598598        url(r'^contact/$', contact_wizard, name='contact'),
    599599    )
     600
     601Advanced ``NamedUrlWizardView`` methods
     602=======================================
     603
     604.. method:: NamedUrlWizardView.get_step_url(step)
     605
     606    This method returns the URL for a specific step.
     607
     608    Default implementation::
     609
     610        def get_step_url(self, step):
     611            return reverse(self.url_name, kwargs={'step': step})
  • django/contrib/formtools/wizard/views.py

     
    586586            'step name "%s" is reserved for "done" view' % initkwargs['done_step_name']
    587587        return initkwargs
    588588
     589    def get_step_url(self, step):
     590        return reverse(self.url_name, kwargs={'step': step})
     591
    589592    def get(self, *args, **kwargs):
    590593        """
    591594        This renders the form or, if needed, does the http redirects.
     
    599602                query_string = "?%s" % self.request.GET.urlencode()
    600603            else:
    601604                query_string = ""
    602             next_step_url = reverse(self.url_name, kwargs={
    603                 'step': self.steps.current,
    604             }) + query_string
    605             return redirect(next_step_url)
     605            return redirect(self.get_step_url(self.steps.current)
     606                            + query_string)
    606607
    607608        # is the current step the "done" name/view?
    608609        elif step_url == self.done_step_name:
     
    631632        # invalid step name, reset to first and redirect.
    632633        else:
    633634            self.storage.current_step = self.steps.first
    634             return redirect(self.url_name, step=self.steps.first)
     635            return redirect(self.get_step_url(self.steps.first))
    635636
    636637    def post(self, *args, **kwargs):
    637638        """
     
    641642        prev_step = self.request.POST.get('wizard_prev_step', None)
    642643        if prev_step and prev_step in self.get_form_list():
    643644            self.storage.current_step = prev_step
    644             return redirect(self.url_name, step=prev_step)
     645            return redirect(self.get_step_url(prev_step))
    645646        return super(NamedUrlWizardView, self).post(*args, **kwargs)
    646647
    647648    def render_next_step(self, form, **kwargs):
     
    651652        """
    652653        next_step = self.get_next_step()
    653654        self.storage.current_step = next_step
    654         return redirect(self.url_name, step=next_step)
     655        return redirect(self.get_step_url(next_step))
    655656
    656657    def render_revalidation_failure(self, failed_step, form, **kwargs):
    657658        """
     
    659660        step.
    660661        """
    661662        self.storage.current_step = failed_step
    662         return redirect(self.url_name, step=failed_step)
     663        return redirect(self.get_step_url(failed_step))
    663664
    664665    def render_done(self, form, **kwargs):
    665666        """
     
    667668        name doesn't fit).
    668669        """
    669670        if kwargs.get('step', None) != self.done_step_name:
    670             return redirect(self.url_name, step=self.done_step_name)
     671            return redirect(self.get_step_url(self.done_step_name))
    671672        return super(NamedUrlWizardView, self).render_done(form, **kwargs)
    672673
    673674
     
    683684    A NamedUrlFormWizard with pre-configured CookieStorageBackend.
    684685    """
    685686    storage_name = 'django.contrib.formtools.wizard.storage.cookie.CookieStorage'
    686 
Back to Top