Django

Code

Changeset 6173

Show
Ignore:
Timestamp:
09/14/07 02:02:55 (1 year ago)
Author:
russellm
Message:

Fiex #5331 -- Modified newforms URLField to prepend http:// if no protocol is specified by the user. Thanks, SmileyChris?.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/newforms/fields.py

    r6156 r6173  
    417417 
    418418    def clean(self, value): 
     419        # If no URL scheme given, assume http:// 
     420        if value and '://' not in value: 
     421            value = u'http://%s' % value 
    419422        value = super(URLField, self).clean(value) 
    420423        if value == u'': 
  • django/trunk/tests/regressiontests/forms/tests.py

    r6156 r6173  
    16241624... 
    16251625ValidationError: [u'Enter a valid URL.'] 
    1626 >>> f.clean('example.com') 
    1627 Traceback (most recent call last): 
    1628 ... 
    1629 ValidationError: [u'Enter a valid URL.'] 
    16301626>>> f.clean('http://') 
    16311627Traceback (most recent call last): 
     
    16581654... 
    16591655ValidationError: [u'Enter a valid URL.'] 
    1660 >>> f.clean('example.com') 
    1661 Traceback (most recent call last): 
    1662 ... 
    1663 ValidationError: [u'Enter a valid URL.'] 
    16641656>>> f.clean('http://') 
    16651657Traceback (most recent call last): 
     
    17141706... 
    17151707ValidationError: [u'Ensure this value has at most 20 characters (it has 37).'] 
     1708 
     1709URLField should prepend 'http://' if no scheme was given 
     1710>>> f = URLField(required=False) 
     1711>>> f.clean('example.com') 
     1712u'http://example.com' 
     1713>>> f.clean('') 
     1714u'' 
     1715>>> f.clean('https://example.com') 
     1716u'https://example.com' 
    17161717 
    17171718# BooleanField ################################################################