Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #6893: `FormWizard` now properly updates its `step` value. Than…

…ks, siddhi and wamberg.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8603 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 70966cb9c7ed97f76be6781e502d08f58a4a0847 1 parent 05133ba
@jacobian jacobian authored
View
43 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 @@ def test_bool_submit(self):
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)
+
View
4 django/contrib/formtools/wizard.py
@@ -92,7 +92,7 @@ def __call__(self, request, *args, **kwargs):
# 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 @@ def render_template(self, request, form, previous_fields, step, context=None):
"""
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,
Please sign in to comment.
Something went wrong with that request. Please try again.