Changeset 5686
- Timestamp:
- 07/13/07 09:13:35 (1 year ago)
- Files:
-
- django/trunk/django/newforms/fields.py (modified) (1 diff)
- django/trunk/tests/regressiontests/forms/localflavor.py (modified) (4 diffs)
- django/trunk/tests/regressiontests/forms/tests.py (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/newforms/fields.py
r5684 r5686 112 112 return u'' 113 113 value = smart_unicode(value) 114 if self.max_length is not None and len(value) > self.max_length: 115 raise ValidationError(ugettext(u'Ensure this value has at most %d characters.') % self.max_length) 116 if self.min_length is not None and len(value) < self.min_length: 117 raise ValidationError(ugettext(u'Ensure this value has at least %d characters.') % self.min_length) 114 value_length = len(value) 115 if self.max_length is not None and value_length > self.max_length: 116 raise ValidationError(ugettext(u'Ensure this value has at most %d characters (it has %d).') % (self.max_length, value_length)) 117 if self.min_length is not None and value_length < self.min_length: 118 raise ValidationError(ugettext(u'Ensure this value has at least %d characters (it has %d).') % (self.min_length, value_length)) 118 119 return value 119 120 django/trunk/tests/regressiontests/forms/localflavor.py
r5663 r5686 914 914 Traceback (most recent call last): 915 915 ... 916 ValidationError: [u'Ensure this value has at most 14 characters .']916 ValidationError: [u'Ensure this value has at most 14 characters (it has 15).'] 917 917 >>> f.clean('123.456.78') 918 918 Traceback (most recent call last): 919 919 ... 920 ValidationError: [u'Ensure this value has at least 11 characters .']920 ValidationError: [u'Ensure this value has at least 11 characters (it has 10).'] 921 921 >>> f.clean('123456789555') 922 922 Traceback (most recent call last): … … 1209 1209 Traceback (most recent call last): 1210 1210 ... 1211 ValidationError: [u'Ensure this value has at least 10 characters .']1211 ValidationError: [u'Ensure this value has at least 10 characters (it has 9).'] 1212 1212 >>> f.clean('230880343234') 1213 1213 Traceback (most recent call last): 1214 1214 ... 1215 ValidationError: [u'Ensure this value has at most 11 characters .']1215 ValidationError: [u'Ensure this value has at most 11 characters (it has 12).'] 1216 1216 >>> f.clean('abcdefghijk') 1217 1217 Traceback (most recent call last): … … 1255 1255 Traceback (most recent call last): 1256 1256 ... 1257 ValidationError: [u'Ensure this value has at least 7 characters .']1257 ValidationError: [u'Ensure this value has at least 7 characters (it has 6).'] 1258 1258 >>> f.clean('123456555') 1259 1259 Traceback (most recent call last): 1260 1260 ... 1261 ValidationError: [u'Ensure this value has at most 8 characters .']1261 ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] 1262 1262 >>> f.clean('abcdefg') 1263 1263 Traceback (most recent call last): … … 1266 1266 Traceback (most recent call last): 1267 1267 ... 1268 ValidationError: [u'Ensure this value has at most 8 characters .']1268 ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] 1269 1269 >>> f.clean(' 12367 ') 1270 1270 Traceback (most recent call last): django/trunk/tests/regressiontests/forms/tests.py
r5680 r5686 897 897 Traceback (most recent call last): 898 898 ... 899 ValidationError: [u'Ensure this value has at most 10 characters .']899 ValidationError: [u'Ensure this value has at most 10 characters (it has 11).'] 900 900 901 901 CharField accepts an optional min_length parameter: … … 906 906 Traceback (most recent call last): 907 907 ... 908 ValidationError: [u'Ensure this value has at least 10 characters .']908 ValidationError: [u'Ensure this value has at least 10 characters (it has 5).'] 909 909 >>> f.clean('1234567890') 910 910 u'1234567890' … … 920 920 Traceback (most recent call last): 921 921 ... 922 ValidationError: [u'Ensure this value has at least 10 characters .']922 ValidationError: [u'Ensure this value has at least 10 characters (it has 5).'] 923 923 >>> f.clean('1234567890') 924 924 u'1234567890' … … 1444 1444 Traceback (most recent call last): 1445 1445 ... 1446 ValidationError: [u'Ensure this value has at least 5 characters .']1446 ValidationError: [u'Ensure this value has at least 5 characters (it has 3).'] 1447 1447 >>> f.clean('abc') 1448 1448 Traceback (most recent call last): 1449 1449 ... 1450 ValidationError: [u'Ensure this value has at least 5 characters .']1450 ValidationError: [u'Ensure this value has at least 5 characters (it has 3).'] 1451 1451 >>> f.clean('12345') 1452 1452 u'12345' … … 1456 1456 Traceback (most recent call last): 1457 1457 ... 1458 ValidationError: [u'Ensure this value has at most 10 characters .']1458 ValidationError: [u'Ensure this value has at most 10 characters (it has 11).'] 1459 1459 >>> f.clean('12345a') 1460 1460 Traceback (most recent call last): … … 1513 1513 Traceback (most recent call last): 1514 1514 ... 1515 ValidationError: [u'Ensure this value has at least 10 characters .']1515 ValidationError: [u'Ensure this value has at least 10 characters (it has 9).'] 1516 1516 >>> f.clean('alf@foo.com') 1517 1517 u'alf@foo.com' … … 1519 1519 Traceback (most recent call last): 1520 1520 ... 1521 ValidationError: [u'Ensure this value has at most 15 characters .']1521 ValidationError: [u'Ensure this value has at most 15 characters (it has 20).'] 1522 1522 1523 1523 # URLField ################################################################## … … 1623 1623 Traceback (most recent call last): 1624 1624 ... 1625 ValidationError: [u'Ensure this value has at least 15 characters .']1625 ValidationError: [u'Ensure this value has at least 15 characters (it has 12).'] 1626 1626 >>> f.clean('http://example.com') 1627 1627 u'http://example.com' … … 1629 1629 Traceback (most recent call last): 1630 1630 ... 1631 ValidationError: [u'Ensure this value has at most 20 characters .']1631 ValidationError: [u'Ensure this value has at most 20 characters (it has 37).'] 1632 1632 1633 1633 # BooleanField ################################################################ … … 1801 1801 Traceback (most recent call last): 1802 1802 ... 1803 ValidationError: [u'Ensure this value has at most 20 characters .']1803 ValidationError: [u'Ensure this value has at most 20 characters (it has 28).'] 1804 1804 >>> f.clean('not an e-mail') 1805 1805 Traceback (most recent call last): … … 1821 1821 Traceback (most recent call last): 1822 1822 ... 1823 ValidationError: [u'Ensure this value has at most 20 characters .']1823 ValidationError: [u'Ensure this value has at most 20 characters (it has 28).'] 1824 1824 >>> f.clean('not an e-mail') 1825 1825 Traceback (most recent call last): … … 3272 3272 <table> 3273 3273 <tr><td colspan="2"><ul class="errorlist"><li>Please make sure your passwords match.</li></ul></td></tr> 3274 <tr><th>Username:</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters .</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr>3274 <tr><th>Username:</th><td><ul class="errorlist"><li>Ensure this value has at most 10 characters (it has 23).</li></ul><input type="text" name="username" value="this-is-a-long-username" maxlength="10" /></td></tr> 3275 3275 <tr><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr> 3276 3276 <tr><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>
