Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #14576 - FormWizard.done() method doesn't get passed the last f…

…orm in the list

Thanks to cyberdelia for report and test, and steph for the initial patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@14574 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit b84838aef4de49c9567c98bd8a8d492e177e5e4f 1 parent b9e6db4
Luke Plant authored
24  django/contrib/formtools/tests/__init__.py
@@ -360,3 +360,27 @@ def process_step(self, request, form, step):
360 360
                 "wizard_step": "1"}
361 361
         wizard(DummyRequest(POST=data))
362 362
 
  363
+    def test_14576(self):
  364
+        """
  365
+        Regression test for ticket #14576.
  366
+
  367
+        The form of the last step is not passed to the done method.
  368
+        """
  369
+        reached = [False]
  370
+        that = self
  371
+
  372
+        class Wizard(WizardClass):
  373
+            def done(self, request, form_list):
  374
+                reached[0] = True
  375
+                that.assertTrue(len(form_list) == 2)
  376
+
  377
+        wizard = Wizard([WizardPageOneForm,
  378
+                         WizardPageTwoForm])
  379
+
  380
+        data = {"0-field": "test",
  381
+                "1-field": "test2",
  382
+                "hash_0": "2fdbefd4c0cad51509478fbacddf8b13",
  383
+                "wizard_step": "1"}
  384
+        wizard(DummyRequest(POST=data))
  385
+        self.assertTrue(reached[0])
  386
+
6  django/contrib/formtools/wizard.py
@@ -116,9 +116,9 @@ def __call__(self, request, *args, **kwargs):
116 116
             # Since the hashes only take into account values, and not other
117 117
             # other validation the form might do, we must re-do validation
118 118
             # now for security reasons.
119  
-            current_form_list = [self.get_form(i, request.POST) for i in range(current_step)]
  119
+            previous_form_list = [self.get_form(i, request.POST) for i in range(current_step)]
120 120
 
121  
-            for i, f in enumerate(current_form_list):
  121
+            for i, f in enumerate(previous_form_list):
122 122
                 if not self._check_security_hash(request.POST.get("hash_%d" % i, ''), request, f):
123 123
                     return self.render_hash_failure(request, i)
124 124
 
@@ -132,7 +132,7 @@ def __call__(self, request, *args, **kwargs):
132 132
             next_step = current_step + 1
133 133
 
134 134
             if next_step == self.num_steps():
135  
-                return self.done(request, current_form_list)
  135
+                return self.done(request, previous_form_list + [form])
136 136
             else:
137 137
                 form = self.get_form(next_step)
138 138
                 self.step = current_step = next_step

0 notes on commit b84838a

Please sign in to comment.
Something went wrong with that request. Please try again.