Author: russellm
Date: 2007-09-14 02:02:55 -0500 (Fri, 14 Sep 2007)
New Revision: 6173
Modified:
django/trunk/django/newforms/fields.py
django/trunk/tests/regressiontests/forms/tests.py
Log:
Fiex #5331 -- Modified newforms URLField to prepend http:// if no protocol is
specified by the user. Thanks, SmileyChris.
Modified: django/trunk/django/newforms/fields.py
===================================================================
--- django/trunk/django/newforms/fields.py 2007-09-14 06:43:46 UTC (rev
6172)
+++ django/trunk/django/newforms/fields.py 2007-09-14 07:02:55 UTC (rev
6173)
@@ -416,6 +416,9 @@
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
Modified: django/trunk/tests/regressiontests/forms/tests.py
===================================================================
--- django/trunk/tests/regressiontests/forms/tests.py 2007-09-14 06:43:46 UTC
(rev 6172)
+++ django/trunk/tests/regressiontests/forms/tests.py 2007-09-14 07:02:55 UTC
(rev 6173)
@@ -1623,10 +1623,6 @@
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 @@
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 @@
...
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()
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---