summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2008-08-26 21:33:56 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2008-08-26 21:33:56 +0000
commit70966cb9c7ed97f76be6781e502d08f58a4a0847 (patch)
tree407490469a5730dfa62b3f208c30210636df31d6
parent05133baaaa9729487c0ce3d7edf02fff4df61169 (diff)
Fixed #6893: `FormWizard` now properly updates its `step` value. Thanks, siddhi and wamberg.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/contrib/formtools/tests.py43
-rw-r--r--django/contrib/formtools/wizard.py4
2 files changed, 44 insertions, 3 deletions
diff --git a/django/contrib/formtools/tests.py b/django/contrib/formtools/tests.py
index b1e2cb7c76..5263e6e598 100644
--- a/django/contrib/formtools/tests.py
+++ b/django/contrib/formtools/tests.py
@@ -1,5 +1,5 @@
from django import forms
-from django.contrib.formtools import preview
+from django.contrib.formtools import preview, wizard
from django import http
from django.test import TestCase
@@ -101,3 +101,44 @@ class PreviewTests(TestCase):
response = self.client.post('/test1/', self.test_data)
self.assertEqual(response.content, success_string)
+#
+# FormWizard tests
+#
+
+class WizardPageOneForm(forms.Form):
+ field = forms.CharField()
+
+class WizardPageTwoForm(forms.Form):
+ field = forms.CharField()
+
+class WizardClass(wizard.FormWizard):
+ def render_template(self, *args, **kw):
+ return ""
+
+ def done(self, request, cleaned_data):
+ return http.HttpResponse(success_string)
+
+class DummyRequest(object):
+ def __init__(self, POST=None):
+ self.method = POST and "POST" or "GET"
+ self.POST = POST
+
+class WizardTests(TestCase):
+ def test_step_starts_at_zero(self):
+ """
+ step should be zero for the first form
+ """
+ wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm])
+ request = DummyRequest()
+ wizard(request)
+ self.assertEquals(0, wizard.step)
+
+ def test_step_increments(self):
+ """
+ step should be incremented when we go to the next page
+ """
+ wizard = WizardClass([WizardPageOneForm, WizardPageTwoForm])
+ request = DummyRequest(POST={"0-field":"test", "wizard_step":"0"})
+ response = wizard(request)
+ self.assertEquals(1, wizard.step)
+
diff --git a/django/contrib/formtools/wizard.py b/django/contrib/formtools/wizard.py
index f764ddd0da..cb64fba537 100644
--- a/django/contrib/formtools/wizard.py
+++ b/django/contrib/formtools/wizard.py
@@ -92,7 +92,7 @@ class FormWizard(object):
# Otherwise, move along to the next step.
else:
form = self.get_form(next_step)
- current_step = next_step
+ self.step = current_step = next_step
return self.render(form, request, current_step)
@@ -203,7 +203,7 @@ class FormWizard(object):
"""
context = context or {}
context.update(self.extra_context)
- return render_to_response(self.get_template(self.step), dict(context,
+ return render_to_response(self.get_template(step), dict(context,
step_field=self.step_field_name,
step0=step,
step=step + 1,