Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #9473: FormWizard now works with NullBooleanFields. As a bonus,…
… we now have the beginnings of a test suite for FormWizard. Thanks, Keith Bussell. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10316 bcc190cf-cafb-0310-a4f2-bffc1f526a37
- Loading branch information
Showing
7 changed files
with
97 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from django import forms | ||
from django.contrib.formtools.wizard import FormWizard | ||
from django.http import HttpResponse | ||
|
||
class Page1(forms.Form): | ||
name = forms.CharField(max_length=100) | ||
thirsty = forms.NullBooleanField() | ||
|
||
class Page2(forms.Form): | ||
address1 = forms.CharField(max_length=100) | ||
address2 = forms.CharField(max_length=100) | ||
|
||
class Page3(forms.Form): | ||
random_crap = forms.CharField(max_length=100) | ||
|
||
class ContactWizard(FormWizard): | ||
def done(self, request, form_list): | ||
return HttpResponse("") |
Empty file.
13 changes: 13 additions & 0 deletions
13
tests/regressiontests/formwizard/templates/forms/wizard.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<html> | ||
<body> | ||
<p>Step {{ step }} of {{ step_count }}</p> | ||
<form action="." method="post"> | ||
<table> | ||
{{ form }} | ||
</table> | ||
<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" /> | ||
{{ previous_fields|safe }} | ||
<input type="submit"> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import re | ||
from django import forms | ||
from django.test import TestCase | ||
|
||
class FormWizardWithNullBooleanField(TestCase): | ||
urls = 'regressiontests.formwizard.urls' | ||
|
||
input_re = re.compile('name="([^"]+)" value="([^"]+)"') | ||
|
||
wizard_url = '/wiz/' | ||
wizard_step_data = ( | ||
{ | ||
'0-name': 'Pony', | ||
'0-thirsty': '2', | ||
}, | ||
{ | ||
'1-address1': '123 Main St', | ||
'1-address2': 'Djangoland', | ||
}, | ||
{ | ||
'2-random_crap': 'blah blah', | ||
} | ||
) | ||
|
||
def grabFieldData(self, response): | ||
""" | ||
Pull the appropriate field data from the context to pass to the next wizard step | ||
""" | ||
previous_fields = response.context['previous_fields'] | ||
fields = {'wizard_step': response.context['step0']} | ||
|
||
def grab(m): | ||
fields[m.group(1)] = m.group(2) | ||
return '' | ||
|
||
self.input_re.sub(grab, previous_fields) | ||
return fields | ||
|
||
def checkWizardStep(self, response, step_no): | ||
""" | ||
Helper function to test each step of the wizard | ||
- Make sure the call succeeded | ||
- Make sure response is the proper step number | ||
- return the result from the post for the next step | ||
""" | ||
step_count = len(self.wizard_step_data) | ||
|
||
self.assertEqual(response.status_code, 200) | ||
self.assertContains(response, 'Step %d of %d' % (step_no, step_count)) | ||
|
||
data = self.grabFieldData(response) | ||
data.update(self.wizard_step_data[step_no - 1]) | ||
|
||
return self.client.post(self.wizard_url, data) | ||
|
||
def testWizard(self): | ||
response = self.client.get(self.wizard_url) | ||
for step_no in range(1, len(self.wizard_step_data) + 1): | ||
response = self.checkWizardStep(response, step_no) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.conf.urls.defaults import * | ||
from forms import ContactWizard, Page1, Page2, Page3 | ||
|
||
urlpatterns = patterns('', | ||
url(r'^wiz/$', ContactWizard([Page1, Page2, Page3])), | ||
) |