Ticket #10882: form_wizard_10882.1.diff
File form_wizard_10882.1.diff, 2.5 KB (added by , 16 years ago) |
---|
-
django/contrib/formtools/wizard.py
58 58 if current_step >= self.num_steps(): 59 59 raise Http404('Step %s does not exist' % current_step) 60 60 61 # Use valid_forms if the done() is called. 62 valid_forms = [] 61 63 # For each previous step, verify the hash and process. 62 64 # TODO: Move "hash_%d" to a method to make it configurable. 63 65 for i in range(current_step): 64 66 form = self.get_form(i, request.POST) 65 67 if request.POST.get("hash_%d" % i, '') != self.security_hash(request, form): 66 68 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) 67 74 self.process_step(request, form, i) 68 75 69 76 # Process the current step. If it's valid, go to the next step or call … … 73 80 else: 74 81 form = self.get_form(current_step) 75 82 if form.is_valid(): 83 valid_forms.append(form) 76 84 self.process_step(request, form, current_step) 77 85 next_step = current_step + 1 78 86 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) 84 90 85 # Validate all the forms. If any of them fail validation, that86 # must mean the validator relied on some other input, such as87 # 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 93 91 # Otherwise, move along to the next step. 94 92 else: 95 93 form = self.get_form(next_step)