Code

Ticket #7439: multipart_form_as_last_in_formwizard.diff

File multipart_form_as_last_in_formwizard.diff, 2.6 KB (added by makoste, 4 years ago)

add raise when multipart form is not as last

Line 
1Index: contrib/formtools/wizard.py
2===================================================================
3--- contrib/formtools/wizard.py (revision 12943)
4+++ contrib/formtools/wizard.py (working copy)
5@@ -42,9 +42,9 @@
6     def __repr__(self):
7         return "step: %d\nform_list: %s\ninitial_data: %s" % (self.step, self.form_list, self.initial)
8 
9-    def get_form(self, step, data=None):
10+    def get_form(self, step, data=None, files=None):
11         "Helper method that returns the Form instance for the given step."
12-        return self.form_list[step](data, prefix=self.prefix_for_step(step), initial=self.initial.get(step, None))
13+        return self.form_list[step](data, files, prefix=self.prefix_for_step(step), initial=self.initial.get(step, None))
14 
15     def num_steps(self):
16         "Helper method that returns the number of steps."
17@@ -71,7 +71,7 @@
18         # For each previous step, verify the hash and process.
19         # TODO: Move "hash_%d" to a method to make it configurable.
20         for i in range(current_step):
21-            form = self.get_form(i, request.POST)
22+            form = self.get_form(i, request.POST, request.FILES)
23             if request.POST.get("hash_%d" % i, '') != self.security_hash(request, form):
24                 return self.render_hash_failure(request, i)
25             self.process_step(request, form, i)
26@@ -79,7 +79,7 @@
27         # Process the current step. If it's valid, go to the next step or call
28         # done(), depending on whether any steps remain.
29         if request.method == 'POST':
30-            form = self.get_form(current_step, request.POST)
31+            form = self.get_form(current_step, request.POST, request.FILES)
32         else:
33             form = self.get_form(current_step)
34         if form.is_valid():
35@@ -90,7 +90,7 @@
36             # time, as a sanity check, and call done().
37             num = self.num_steps()
38             if next_step == num:
39-                final_form_list = [self.get_form(i, request.POST) for i in range(num)]
40+                final_form_list = [self.get_form(i, request.POST, request.FILES) for i in range(num)]
41 
42                 # Validate all the forms. If any of them fail validation, that
43                 # must mean the validator relied on some other input, such as
44@@ -102,6 +102,8 @@
45 
46             # Otherwise, move along to the next step.
47             else:
48+                if form.is_multipart():
49+                    raise NotImplementedError("Your %s class has not initialized multipart form as last." % self.__class__.__name__)
50                 form = self.get_form(next_step)
51                 self.step = current_step = next_step
52