Django

Code

Changeset 5686

Show
Ignore:
Timestamp:
07/13/07 09:13:35 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4469 -- Added slightly more informative error messages to max- and
min-length newform validation. Based on a patch from A. Murat Eren.

Files:

Legend:

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

    r5684 r5686  
    112112            return u'' 
    113113        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)) 
    118119        return value 
    119120 
  • django/trunk/tests/regressiontests/forms/localflavor.py

    r5663 r5686  
    914914Traceback (most recent call last): 
    915915... 
    916 ValidationError: [u'Ensure this value has at most 14 characters.'] 
     916ValidationError: [u'Ensure this value has at most 14 characters (it has 15).'] 
    917917>>> f.clean('123.456.78') 
    918918Traceback (most recent call last): 
    919919... 
    920 ValidationError: [u'Ensure this value has at least 11 characters.'] 
     920ValidationError: [u'Ensure this value has at least 11 characters (it has 10).'] 
    921921>>> f.clean('123456789555') 
    922922Traceback (most recent call last): 
     
    12091209Traceback (most recent call last): 
    12101210... 
    1211 ValidationError: [u'Ensure this value has at least 10 characters.'] 
     1211ValidationError: [u'Ensure this value has at least 10 characters (it has 9).'] 
    12121212>>> f.clean('230880343234') 
    12131213Traceback (most recent call last): 
    12141214... 
    1215 ValidationError: [u'Ensure this value has at most 11 characters.'] 
     1215ValidationError: [u'Ensure this value has at most 11 characters (it has 12).'] 
    12161216>>> f.clean('abcdefghijk') 
    12171217Traceback (most recent call last): 
     
    12551255Traceback (most recent call last): 
    12561256... 
    1257 ValidationError: [u'Ensure this value has at least 7 characters.'] 
     1257ValidationError: [u'Ensure this value has at least 7 characters (it has 6).'] 
    12581258>>> f.clean('123456555') 
    12591259Traceback (most recent call last): 
    12601260... 
    1261 ValidationError: [u'Ensure this value has at most 8 characters.'] 
     1261ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] 
    12621262>>> f.clean('abcdefg') 
    12631263Traceback (most recent call last): 
     
    12661266Traceback (most recent call last): 
    12671267... 
    1268 ValidationError: [u'Ensure this value has at most 8 characters.'] 
     1268ValidationError: [u'Ensure this value has at most 8 characters (it has 9).'] 
    12691269>>> f.clean(' 12367  ') 
    12701270Traceback (most recent call last): 
  • django/trunk/tests/regressiontests/forms/tests.py

    r5680 r5686  
    897897Traceback (most recent call last): 
    898898... 
    899 ValidationError: [u'Ensure this value has at most 10 characters.'] 
     899ValidationError: [u'Ensure this value has at most 10 characters (it has 11).'] 
    900900 
    901901CharField accepts an optional min_length parameter: 
     
    906906Traceback (most recent call last): 
    907907... 
    908 ValidationError: [u'Ensure this value has at least 10 characters.'] 
     908ValidationError: [u'Ensure this value has at least 10 characters (it has 5).'] 
    909909>>> f.clean('1234567890') 
    910910u'1234567890' 
     
    920920Traceback (most recent call last): 
    921921... 
    922 ValidationError: [u'Ensure this value has at least 10 characters.'] 
     922ValidationError: [u'Ensure this value has at least 10 characters (it has 5).'] 
    923923>>> f.clean('1234567890') 
    924924u'1234567890' 
     
    14441444Traceback (most recent call last): 
    14451445... 
    1446 ValidationError: [u'Ensure this value has at least 5 characters.'] 
     1446ValidationError: [u'Ensure this value has at least 5 characters (it has 3).'] 
    14471447>>> f.clean('abc') 
    14481448Traceback (most recent call last): 
    14491449... 
    1450 ValidationError: [u'Ensure this value has at least 5 characters.'] 
     1450ValidationError: [u'Ensure this value has at least 5 characters (it has 3).'] 
    14511451>>> f.clean('12345') 
    14521452u'12345' 
     
    14561456Traceback (most recent call last): 
    14571457... 
    1458 ValidationError: [u'Ensure this value has at most 10 characters.'] 
     1458ValidationError: [u'Ensure this value has at most 10 characters (it has 11).'] 
    14591459>>> f.clean('12345a') 
    14601460Traceback (most recent call last): 
     
    15131513Traceback (most recent call last): 
    15141514... 
    1515 ValidationError: [u'Ensure this value has at least 10 characters.'] 
     1515ValidationError: [u'Ensure this value has at least 10 characters (it has 9).'] 
    15161516>>> f.clean('alf@foo.com') 
    15171517u'alf@foo.com' 
     
    15191519Traceback (most recent call last): 
    15201520... 
    1521 ValidationError: [u'Ensure this value has at most 15 characters.'] 
     1521ValidationError: [u'Ensure this value has at most 15 characters (it has 20).'] 
    15221522 
    15231523# URLField ################################################################## 
     
    16231623Traceback (most recent call last): 
    16241624... 
    1625 ValidationError: [u'Ensure this value has at least 15 characters.'] 
     1625ValidationError: [u'Ensure this value has at least 15 characters (it has 12).'] 
    16261626>>> f.clean('http://example.com') 
    16271627u'http://example.com' 
     
    16291629Traceback (most recent call last): 
    16301630... 
    1631 ValidationError: [u'Ensure this value has at most 20 characters.'] 
     1631ValidationError: [u'Ensure this value has at most 20 characters (it has 37).'] 
    16321632 
    16331633# BooleanField ################################################################ 
     
    18011801Traceback (most recent call last): 
    18021802... 
    1803 ValidationError: [u'Ensure this value has at most 20 characters.'] 
     1803ValidationError: [u'Ensure this value has at most 20 characters (it has 28).'] 
    18041804>>> f.clean('not an e-mail') 
    18051805Traceback (most recent call last): 
     
    18211821Traceback (most recent call last): 
    18221822... 
    1823 ValidationError: [u'Ensure this value has at most 20 characters.'] 
     1823ValidationError: [u'Ensure this value has at most 20 characters (it has 28).'] 
    18241824>>> f.clean('not an e-mail') 
    18251825Traceback (most recent call last): 
     
    32723272<table> 
    32733273<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> 
    32753275<tr><th>Password1:</th><td><input type="password" name="password1" value="foo" /></td></tr> 
    32763276<tr><th>Password2:</th><td><input type="password" name="password2" value="bar" /></td></tr>