Ticket #10882: form_wizard_10882.1.diff

File form_wizard_10882.1.diff, 2.5 KB (added by jashugan, 15 years ago)

First attempt.

  • django/contrib/formtools/wizard.py

     
    5858        if current_step >= self.num_steps():
    5959            raise Http404('Step %s does not exist' % current_step)
    6060
     61        # Use valid_forms if the done() is called.
     62        valid_forms = []
    6163        # For each previous step, verify the hash and process.
    6264        # TODO: Move "hash_%d" to a method to make it configurable.
    6365        for i in range(current_step):
    6466            form = self.get_form(i, request.POST)
    6567            if request.POST.get("hash_%d" % i, '') != self.security_hash(request, form):
    6668                return self.render_hash_failure(request, i)
     69            # process_step needs a clean, valid form. So, validate all the forms.
     70            # Also serves as a sanity check.
     71            if not form.is_valid():
     72                return self.render_revalidation_failure(request, i, form)
     73            valid_forms.append(form)
    6774            self.process_step(request, form, i)
    6875
    6976        # Process the current step. If it's valid, go to the next step or call
     
    7380        else:
    7481            form = self.get_form(current_step)
    7582        if form.is_valid():
     83            valid_forms.append(form)
    7684            self.process_step(request, form, current_step)
    7785            next_step = current_step + 1
    7886
    79             # If this was the last step, validate all of the forms one more
    80             # time, as a sanity check, and call done().
    81             num = self.num_steps()
    82             if next_step == num:
    83                 final_form_list = [self.get_form(i, request.POST) for i in range(num)]
     87            # If this was the last step, call done() with final list of validated forms.
     88            if next_step == self.num_steps():
     89                return self.done(request, valid_forms)
    8490
    85                 # Validate all the forms. If any of them fail validation, that
    86                 # must mean the validator relied on some other input, such as
    87                 # an external Web site.
    88                 for i, f in enumerate(final_form_list):
    89                     if not f.is_valid():
    90                         return self.render_revalidation_failure(request, i, f)
    91                 return self.done(request, final_form_list)
    92 
    9391            # Otherwise, move along to the next step.
    9492            else:
    9593                form = self.get_form(next_step)
Back to Top