summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRamiro Morales <cramm0@gmail.com>2010-12-23 15:32:59 +0000
committerRamiro Morales <cramm0@gmail.com>2010-12-23 15:32:59 +0000
commit6c32577d31cdb26fa83c22bb3276e850447e196a (patch)
treec869ad82f6bd68120f8772ff0ad47b0b48dee54a
parent56007af3213a96889c10e56ab2ac1a7ef862410a (diff)
[1.2.X] Fixed #14576, #14946 - 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. Backport of r14574 from trunk. git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@15044 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/formtools/tests.py25
-rw-r--r--django/contrib/formtools/wizard.py6
2 files changed, 27 insertions, 4 deletions
diff --git a/django/contrib/formtools/tests.py b/django/contrib/formtools/tests.py
index 7816c15bf5..9894e5bec6 100644
--- a/django/contrib/formtools/tests.py
+++ b/django/contrib/formtools/tests.py
@@ -116,7 +116,7 @@ class SecurityHashTests(unittest.TestCase):
hash1 = utils.security_hash(None, f1)
hash2 = utils.security_hash(None, f2)
self.assertEqual(hash1, hash2)
-
+
def test_empty_permitted(self):
"""
Regression test for #10643: the security hash should allow forms with
@@ -214,3 +214,26 @@ class WizardTests(TestCase):
wizard(DummyRequest(POST=data))
self.assertTrue(reached[0])
+ 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])
diff --git a/django/contrib/formtools/wizard.py b/django/contrib/formtools/wizard.py
index f86dbad70b..2dac2c07eb 100644
--- a/django/contrib/formtools/wizard.py
+++ b/django/contrib/formtools/wizard.py
@@ -94,9 +94,9 @@ class FormWizard(object):
# 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 request.POST.get("hash_%d" % i, '') != self.security_hash(request, f):
return self.render_hash_failure(request, i)
@@ -111,7 +111,7 @@ class FormWizard(object):
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