From 7d3ae27cacc341c468f0df0b03ea8ff83a3787f5 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 24 Jan 2007 05:25:02 +0000 Subject: [PATCH] newforms-admin: *Really* merged to [4411] git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@4413 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/forms/tests.py | 99 ++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 389b076ddd..95e8b59c01 100644 --- a/tests/regressiontests/forms/tests.py +++ b/tests/regressiontests/forms/tests.py @@ -336,6 +336,40 @@ If 'choices' is passed to both the constructor and render(), then they'll both b >>> w.render('email', 'ŠĐĆŽćžšđ', choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]) u'' +# NullBooleanSelect Widget #################################################### + +>>> w = NullBooleanSelect() +>>> print w.render('is_cool', True) + +>>> print w.render('is_cool', False) + +>>> print w.render('is_cool', None) + +>>> print w.render('is_cool', '2') + +>>> print w.render('is_cool', '3') + + # SelectMultiple Widget ####################################################### >>> w = SelectMultiple() @@ -1463,6 +1497,20 @@ Traceback (most recent call last): ... ValidationError: [u'Select a valid choice. John is not one of the available choices.'] +# NullBooleanField ############################################################ + +>>> f = NullBooleanField() +>>> f.clean('') +>>> f.clean(True) +True +>>> f.clean(False) +False +>>> f.clean(None) +>>> f.clean('1') +>>> f.clean('2') +>>> f.clean('3') +>>> f.clean('hello') + # MultipleChoiceField ######################################################### >>> f = MultipleChoiceField(choices=[('1', '1'), ('2', '2')]) @@ -2601,6 +2649,57 @@ True >>> p.clean_data {'first_name': u'John', 'last_name': u'Lennon', 'birthday': datetime.date(1940, 10, 9)} +# Forms with NullBooleanFields ################################################ + +NullBooleanField is a bit of a special case because its presentation (widget) +is different than its data. This is handled transparently, though. + +>>> class Person(Form): +... name = CharField() +... is_cool = NullBooleanField() +>>> p = Person({'name': u'Joe'}, auto_id=False) +>>> print p['is_cool'] + +>>> p = Person({'name': u'Joe', 'is_cool': u'1'}, auto_id=False) +>>> print p['is_cool'] + +>>> p = Person({'name': u'Joe', 'is_cool': u'2'}, auto_id=False) +>>> print p['is_cool'] + +>>> p = Person({'name': u'Joe', 'is_cool': u'3'}, auto_id=False) +>>> print p['is_cool'] + +>>> p = Person({'name': u'Joe', 'is_cool': True}, auto_id=False) +>>> print p['is_cool'] + +>>> p = Person({'name': u'Joe', 'is_cool': False}, auto_id=False) +>>> print p['is_cool'] + + # Basic form processing in a view ############################################# >>> from django.template import Template, Context