mirror of
https://github.com/django/django.git
synced 2025-07-31 09:05:33 +00:00
Implented newforms USStateField in django.contrib.localflavor.usa. Refs #2455
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4525 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
27b28616b4
commit
1ce1442d95
3 changed files with 245 additions and 1 deletions
|
@ -3282,6 +3282,51 @@ u''
|
|||
>>> f.clean('')
|
||||
u''
|
||||
|
||||
# USStateField ################################################################
|
||||
|
||||
USStateField validates that the data is either an abbreviation or name of a
|
||||
U.S. state.
|
||||
>>> from django.contrib.localflavor.usa.forms import USStateField
|
||||
>>> f = USStateField()
|
||||
>>> f.clean('il')
|
||||
u'IL'
|
||||
>>> f.clean('IL')
|
||||
u'IL'
|
||||
>>> f.clean('illinois')
|
||||
u'IL'
|
||||
>>> f.clean(' illinois ')
|
||||
u'IL'
|
||||
>>> f.clean(60606)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a U.S. state or territory.']
|
||||
>>> f.clean(None)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
>>> f.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
|
||||
>>> f = USStateField(required=False)
|
||||
>>> f.clean('il')
|
||||
u'IL'
|
||||
>>> f.clean('IL')
|
||||
u'IL'
|
||||
>>> f.clean('illinois')
|
||||
u'IL'
|
||||
>>> f.clean(' illinois ')
|
||||
u'IL'
|
||||
>>> f.clean(60606)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a U.S. state or territory.']
|
||||
>>> f.clean(None)
|
||||
u''
|
||||
>>> f.clean('')
|
||||
u''
|
||||
|
||||
#################################
|
||||
# Tests of underlying functions #
|
||||
#################################
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue