Ticket #12884: form_wizard.diff

File form_wizard.diff, 1.4 KB (added by Anand Kumria <wildfire@…>, 15 years ago)

patch to allow backwards traversal in FormWizard

  • django/contrib/formtools/wizard.py

    diff --git a/django/contrib/formtools/wizard.py b/django/contrib/formtools/wizard.py
    index b97e090..c18d7ff 100644
    a b class FormWizard(object):  
    7676            form = self.get_form(current_step, request.POST)
    7777        else:
    7878            form = self.get_form(current_step)
    79         if form.is_valid():
     79        if self.advance_form(request, form, current_step) and form.is_valid():
    8080            self.process_step(request, form, current_step)
    8181            next_step = current_step + 1
    8282
    class FormWizard(object):  
    217217            previous_fields=previous_fields
    218218        ), context_instance=RequestContext(request))
    219219
     220    def advance_form(self, request, form, step):
     221        """
     222        Hook to decide if the next form in the list should be displayed.
     223
     224        There are occassions when you may want to have a form with a button
     225        that goes backwards. You can make the boolean decision to advance
     226        to the next form, typically, using the existing form and the
     227        current request.
     228
     229        The rationale is that you may want to include the existing form data
     230        when the form is being redisplayed.
     231        """
     232        return True
     233
    220234    def process_step(self, request, form, step):
    221235        """
    222236        Hook for modifying the FormWizard's internal state, given a fully
Back to Top