Fiex #5331 -- Modified newforms URLField to prepend http:// if no protocol is specified by the user. Thanks, SmileyChris.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@6173 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3358e2fec7
commit
20ecbbd9e7
|
@ -416,6 +416,9 @@ class URLField(RegexField):
|
|||
self.user_agent = validator_user_agent
|
||||
|
||||
def clean(self, value):
|
||||
# If no URL scheme given, assume http://
|
||||
if value and '://' not in value:
|
||||
value = u'http://%s' % value
|
||||
value = super(URLField, self).clean(value)
|
||||
if value == u'':
|
||||
return value
|
||||
|
|
|
@ -1623,10 +1623,6 @@ u'http://200.8.9.10:8000/test'
|
|||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid URL.']
|
||||
>>> f.clean('example.com')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid URL.']
|
||||
>>> f.clean('http://')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
|
@ -1657,10 +1653,6 @@ u'http://www.example.com'
|
|||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid URL.']
|
||||
>>> f.clean('example.com')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValidationError: [u'Enter a valid URL.']
|
||||
>>> f.clean('http://')
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
|
@ -1714,6 +1706,15 @@ Traceback (most recent call last):
|
|||
...
|
||||
ValidationError: [u'Ensure this value has at most 20 characters (it has 37).']
|
||||
|
||||
URLField should prepend 'http://' if no scheme was given
|
||||
>>> f = URLField(required=False)
|
||||
>>> f.clean('example.com')
|
||||
u'http://example.com'
|
||||
>>> f.clean('')
|
||||
u''
|
||||
>>> f.clean('https://example.com')
|
||||
u'https://example.com'
|
||||
|
||||
# BooleanField ################################################################
|
||||
|
||||
>>> f = BooleanField()
|
||||
|
|
Loading…
Reference in New Issue