Changeset 8089
- Timestamp:
- 07/26/08 00:18:39 (4 months ago)
- Files:
-
- django/trunk/django/forms/fields.py (modified) (2 diffs)
- django/trunk/tests/regressiontests/forms/fields.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/forms/fields.py
r8046 r8089 8 8 import re 9 9 import time 10 import urlparse 10 11 try: 11 12 from cStringIO import StringIO … … 540 541 if value and '://' not in value: 541 542 value = u'http://%s' % value 543 # If no URL path given, assume / 544 if value and not urlparse.urlsplit(value).path: 545 value += '/' 542 546 value = super(URLField, self).clean(value) 543 547 if value == u'': django/trunk/tests/regressiontests/forms/fields.py
r7987 r8089 821 821 ValidationError: [u'This field is required.'] 822 822 >>> f.clean('http://localhost') 823 u'http://localhost '823 u'http://localhost/' 824 824 >>> f.clean('http://example.com') 825 u'http://example.com '825 u'http://example.com/' 826 826 >>> f.clean('http://www.example.com') 827 u'http://www.example.com '827 u'http://www.example.com/' 828 828 >>> f.clean('http://www.example.com:8000/test') 829 829 u'http://www.example.com:8000/test' 830 830 >>> f.clean('http://200.8.9.10') 831 u'http://200.8.9.10 '831 u'http://200.8.9.10/' 832 832 >>> f.clean('http://200.8.9.10:8000/test') 833 833 u'http://200.8.9.10:8000/test' … … 859 859 u'' 860 860 >>> f.clean('http://example.com') 861 u'http://example.com '861 u'http://example.com/' 862 862 >>> f.clean('http://www.example.com') 863 u'http://www.example.com '863 u'http://www.example.com/' 864 864 >>> f.clean('foo') 865 865 Traceback (most recent call last): … … 887 887 >>> f = URLField(verify_exists=True) 888 888 >>> f.clean('http://www.google.com') # This will fail if there's no Internet connection 889 u'http://www.google.com '889 u'http://www.google.com/' 890 890 >>> f.clean('http://example') 891 891 Traceback (most recent call last): … … 904 904 u'' 905 905 >>> f.clean('http://www.google.com') # This will fail if there's no Internet connection 906 u'http://www.google.com '906 u'http://www.google.com/' 907 907 908 908 URLField also access min_length and max_length parameters, for convenience. … … 911 911 Traceback (most recent call last): 912 912 ... 913 ValidationError: [u'Ensure this value has at least 15 characters (it has 1 2).']913 ValidationError: [u'Ensure this value has at least 15 characters (it has 13).'] 914 914 >>> f.clean('http://example.com') 915 u'http://example.com '915 u'http://example.com/' 916 916 >>> f.clean('http://abcdefghijklmnopqrstuvwxyz.com') 917 917 Traceback (most recent call last): 918 918 ... 919 ValidationError: [u'Ensure this value has at most 20 characters (it has 3 7).']919 ValidationError: [u'Ensure this value has at most 20 characters (it has 38).'] 920 920 921 921 URLField should prepend 'http://' if no scheme was given 922 922 >>> f = URLField(required=False) 923 923 >>> f.clean('example.com') 924 u'http://example.com '924 u'http://example.com/' 925 925 >>> f.clean('') 926 926 u'' 927 927 >>> f.clean('https://example.com') 928 u'https://example.com' 928 u'https://example.com/' 929 930 URLField should append '/' if no path was given 931 >>> f = URLField() 932 >>> f.clean('http://example.com') 933 u'http://example.com/' 934 935 URLField shouldn't change the path if it was given 936 >>> f.clean('http://example.com/test') 937 u'http://example.com/test' 929 938 930 939 # BooleanField ################################################################
