Ticket #9473: fix_9473.diff

File fix_9473.diff, 4.5 KB (added by Keith Bussell, 16 years ago)

Fix and test

  • django/forms/widgets.py

     
    422422
    423423    def value_from_datadict(self, data, files, name):
    424424        value = data.get(name, None)
    425         return {u'2': True, u'3': False, True: True, False: False}.get(value, None)
     425        return {u'2': True, u'3': False, 'True': True, 'False': False}.get(value, None)
    426426
    427427    def _has_changed(self, initial, data):
    428428        # Sometimes data or initial could be None or u'' which should be the
  • tests/regressiontests/formwizard/forms.py

     
     1from django import forms
     2from django.contrib.formtools.wizard import FormWizard
     3from django.http import HttpResponse
     4
     5class Page1(forms.Form):
     6    name = forms.CharField(max_length=100)
     7    thirsty = forms.NullBooleanField()
     8
     9class Page2(forms.Form):
     10    address1 = forms.CharField(max_length=100)
     11    address2 = forms.CharField(max_length=100)
     12   
     13class Page3(forms.Form):
     14    random_crap = forms.CharField(max_length=100)
     15   
     16class ContactWizard(FormWizard):
     17    def done(self, request, form_list):
     18        return HttpResponse("")
  • tests/regressiontests/formwizard/templates/forms/wizard.html

     
     1<html>
     2  <body>
     3    <p>Step {{ step }} of {{ step_count }}</p>
     4    <form action="." method="post">
     5    <table>
     6    {{ form }}
     7    </table>
     8    <input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />
     9    {{ previous_fields|safe }}
     10    <input type="submit">
     11    </form>
     12  </body>
     13</html>
     14 No newline at end of file
  • tests/regressiontests/formwizard/tests.py

     
     1import re
     2from django import forms
     3from django.test import TestCase
     4
     5class FormWizardWithNullBooleanField(TestCase):
     6    urls = 'regressiontests.formwizard.urls'
     7
     8    input_re = re.compile('<input (?:type="[^"]+" )?name="([^"]+)" value="([^"]+)"')
     9
     10    def grabInputFields(self, response_content):
     11        fields = {}
     12        start_pos = 0
     13        m = 'dummy'
     14        while m:
     15            response_content = response_content[start_pos:]
     16            m = self.input_re.search(response_content)
     17            if m:
     18                fields[m.group(1)] = m.group(2)
     19                start_pos = m.end()
     20        return fields
     21
     22    def testWizard(self):
     23        url = '/wiz/'
     24        response = self.client.get(url)
     25        self.assertContains(response, 'Step 1 of 3')
     26       
     27        data = self.grabInputFields(response.content)
     28        data.update({
     29            '0-name': 'Pony',
     30            '0-thirsty': '2',
     31        })
     32        response = self.client.post(url, data)
     33        self.assertContains(response, 'Step 2 of 3')
     34       
     35        data = self.grabInputFields(response.content)
     36        data.update({
     37            '1-address1': '123 Main St',
     38            '1-address2': 'Djangoland',
     39        })
     40
     41        response = self.client.post(url, data)
     42        self.assertContains(response, 'Step 3 of 3')
     43
     44        data = self.grabInputFields(response.content)       
     45        data = {
     46            '2-random_crap': 'blah blah',
     47        }
     48        response = self.client.post(url, data)
     49        self.assertEqual(response.status_code, 200)
     50       
     51 No newline at end of file
  • tests/regressiontests/formwizard/urls.py

     
     1from django.conf.urls.defaults import *
     2from forms import ContactWizard, Page1, Page2, Page3
     3
     4urlpatterns = patterns('',
     5    url(r'^wiz/$', ContactWizard([Page1, Page2, Page3])),
     6    )
Back to Top