Author: lukeplant
Date: 2010-11-16 08:37:00 -0600 (Tue, 16 Nov 2010)
New Revision: 14574

Modified:
   django/trunk/django/contrib/formtools/tests/__init__.py
   django/trunk/django/contrib/formtools/wizard.py
Log:
Fixed #14576 - FormWizard.done() method doesn't get passed the last form in the 
list

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

Modified: django/trunk/django/contrib/formtools/tests/__init__.py
===================================================================
--- django/trunk/django/contrib/formtools/tests/__init__.py     2010-11-16 
14:00:38 UTC (rev 14573)
+++ django/trunk/django/contrib/formtools/tests/__init__.py     2010-11-16 
14:37:00 UTC (rev 14574)
@@ -360,3 +360,27 @@
                 "wizard_step": "1"}
         wizard(DummyRequest(POST=data))
 
+    def test_14576(self):
+        """
+        Regression test for ticket #14576.
+
+        The form of the last step is not passed to the done method.
+        """
+        reached = [False]
+        that = self
+
+        class Wizard(WizardClass):
+            def done(self, request, form_list):
+                reached[0] = True
+                that.assertTrue(len(form_list) == 2)
+
+        wizard = Wizard([WizardPageOneForm,
+                         WizardPageTwoForm])
+
+        data = {"0-field": "test",
+                "1-field": "test2",
+                "hash_0": "2fdbefd4c0cad51509478fbacddf8b13",
+                "wizard_step": "1"}
+        wizard(DummyRequest(POST=data))
+        self.assertTrue(reached[0])
+

Modified: django/trunk/django/contrib/formtools/wizard.py
===================================================================
--- django/trunk/django/contrib/formtools/wizard.py     2010-11-16 14:00:38 UTC 
(rev 14573)
+++ django/trunk/django/contrib/formtools/wizard.py     2010-11-16 14:37:00 UTC 
(rev 14574)
@@ -116,9 +116,9 @@
             # Since the hashes only take into account values, and not other
             # other validation the form might do, we must re-do validation
             # now for security reasons.
-            current_form_list = [self.get_form(i, request.POST) for i in 
range(current_step)]
+            previous_form_list = [self.get_form(i, request.POST) for i in 
range(current_step)]
 
-            for i, f in enumerate(current_form_list):
+            for i, f in enumerate(previous_form_list):
                 if not self._check_security_hash(request.POST.get("hash_%d" % 
i, ''), request, f):
                     return self.render_hash_failure(request, i)
 
@@ -132,7 +132,7 @@
             next_step = current_step + 1
 
             if next_step == self.num_steps():
-                return self.done(request, current_form_list)
+                return self.done(request, previous_form_list + [form])
             else:
                 form = self.get_form(next_step)
                 self.step = current_step = next_step

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to