Django

Code

Show
Ignore:
Timestamp:
12/17/07 02:05:27 (1 year ago)
Author:
mtredinnick
Message:

Fixed #5871 -- Factored out the validation errors in localflavor form fields. Brings them into line with the standard newforms fields. Patch from Jan Rademaker.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/localflavor/no/forms.py

    r5876 r6926  
    99 
    1010class NOZipCodeField(RegexField): 
     11    default_error_messages = { 
     12        'invalid': ugettext('Enter a zip code in the format XXXX.'), 
     13    } 
     14 
    1115    def __init__(self, *args, **kwargs): 
    1216        super(NOZipCodeField, self).__init__(r'^\d{4}$', 
    13             max_length=None, min_length=None, 
    14             error_message=ugettext('Enter a zip code in the format XXXX.'), 
    15                     *args, **kwargs) 
     17            max_length=None, min_length=None, *args, **kwargs) 
    1618 
    1719class NOMunicipalitySelect(Select): 
     
    2830    Algorithm is documented at http://no.wikipedia.org/wiki/Personnummer 
    2931    """ 
     32    default_error_messages = { 
     33        'invalid': ugettext(u'Enter a valid Norwegian social security number.'), 
     34    } 
     35 
    3036    def clean(self, value): 
    3137        super(NOSocialSecurityNumber, self).clean(value) 
     
    3339            return u'' 
    3440 
    35         msg = ugettext(u'Enter a valid Norwegian social security number.') 
    3641        if not re.match(r'^\d{11}$', value): 
    37             raise ValidationError(msg
     42            raise ValidationError(self.error_messages['invalid']
    3843 
    3944        day = int(value[:2]) 
     
    5358                self.birthday = datetime.date(1900+year2, month, day) 
    5459        except ValueError: 
    55             raise ValidationError(msg
     60            raise ValidationError(self.error_messages['invalid']
    5661 
    5762        sexnum = int(value[8]) 
     
    6974 
    7075        if multiply_reduce(digits, weight_1) % 11 != 0: 
    71             raise ValidationError(msg
     76            raise ValidationError(self.error_messages['invalid']
    7277        if multiply_reduce(digits, weight_2) % 11 != 0: 
    73             raise ValidationError(msg
     78            raise ValidationError(self.error_messages['invalid']
    7479 
    7580        return value