mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
newforms-admin: Merged to [6370].
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6371 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -2945,6 +2945,37 @@ is default behavior.
|
||||
<li><label for="id_username">Username:</label> <input id="id_username" type="text" name="username" maxlength="10" /></li>
|
||||
<li><label for="id_password">Password:</label> <input type="password" name="password" id="id_password" /></li>
|
||||
|
||||
|
||||
# Label Suffix ################################################################
|
||||
|
||||
You can specify the 'label_suffix' argument to a Form class to modify the
|
||||
punctuation symbol used at the end of a label. By default, the colon (:) is
|
||||
used, and is only appended to the label if the label doesn't already end with a
|
||||
punctuation symbol: ., !, ? or :. If you specify a different suffix, it will
|
||||
be appended regardless of the last character of the label.
|
||||
|
||||
>>> class FavoriteForm(Form):
|
||||
... color = CharField(label='Favorite color?')
|
||||
... animal = CharField(label='Favorite animal')
|
||||
...
|
||||
>>> f = FavoriteForm(auto_id=False)
|
||||
>>> print f.as_ul()
|
||||
<li>Favorite color? <input type="text" name="color" /></li>
|
||||
<li>Favorite animal: <input type="text" name="animal" /></li>
|
||||
>>> f = FavoriteForm(auto_id=False, label_suffix='?')
|
||||
>>> print f.as_ul()
|
||||
<li>Favorite color? <input type="text" name="color" /></li>
|
||||
<li>Favorite animal? <input type="text" name="animal" /></li>
|
||||
>>> f = FavoriteForm(auto_id=False, label_suffix='')
|
||||
>>> print f.as_ul()
|
||||
<li>Favorite color? <input type="text" name="color" /></li>
|
||||
<li>Favorite animal <input type="text" name="animal" /></li>
|
||||
>>> f = FavoriteForm(auto_id=False, label_suffix=u'\u2192')
|
||||
>>> f.as_ul()
|
||||
u'<li>Favorite color? <input type="text" name="color" /></li>\n<li>Favorite animal\u2192 <input type="text" name="animal" /></li>'
|
||||
|
||||
|
||||
|
||||
# Initial data ################################################################
|
||||
|
||||
You can specify initial data for a field by using the 'initial' argument to a
|
||||
@@ -3805,6 +3836,61 @@ ValidationError: [u'This field is required.']
|
||||
>>> f.cleaned_data
|
||||
{'field1': u'some text,JP,2007-04-25 06:24:00'}
|
||||
|
||||
|
||||
# IPAddressField ##################################################################
|
||||
|
||||
>>> f = IPAddressField()
|
||||
>>> f.clean('')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
>>> f.clean(None)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'This field is required.']
|
||||
>>> f.clean('127.0.0.1')
|
||||
u'127.0.0.1'
|
||||
>>> f.clean('foo')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
>>> f.clean('127.0.0.')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
>>> f.clean('1.2.3.4.5')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
>>> f.clean('256.125.1.5')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
|
||||
>>> f = IPAddressField(required=False)
|
||||
>>> f.clean('')
|
||||
u''
|
||||
>>> f.clean(None)
|
||||
u''
|
||||
>>> f.clean('127.0.0.1')
|
||||
u'127.0.0.1'
|
||||
>>> f.clean('foo')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
>>> f.clean('127.0.0.')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
>>> f.clean('1.2.3.4.5')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
>>> f.clean('256.125.1.5')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid IPv4 address.']
|
||||
|
||||
#################################
|
||||
# Tests of underlying functions #
|
||||
#################################
|
||||
|
||||
Reference in New Issue
Block a user