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/za/forms.py

    r6843 r6926  
    1717    check for the birthdate 
    1818    """ 
    19  
    20     def __init__(self, *args, **kwargs): 
    21         super(ZAIDField, self).__init__() 
    22         self.error_message = _(u'Enter a valid South African ID number') 
     19    default_error_messages = { 
     20        'invalid': _(u'Enter a valid South African ID number'), 
     21    } 
    2322 
    2423    def clean(self, value): 
     
    3231 
    3332        match = re.match(id_re, value) 
    34          
     33 
    3534        if not match: 
    36             raise ValidationError(self.error_message
     35            raise ValidationError(self.error_messages['invalid']
    3736 
    3837        g = match.groupdict() 
     
    4443            d = date(int(g['yy']) + 2000, int(g['mm']), int(g['dd'])) 
    4544        except ValueError: 
    46             raise ValidationError(self.error_message
     45            raise ValidationError(self.error_messages['invalid']
    4746 
    4847        if not luhn(value): 
    49             raise ValidationError(self.error_message
     48            raise ValidationError(self.error_messages['invalid']
    5049 
    5150        return value 
    5251 
    5352class ZAPostCodeField(RegexField): 
     53    default_error_messages = { 
     54        'invalid': _(u'Enter a valid South African postal code'), 
     55    } 
     56 
    5457    def __init__(self, *args, **kwargs): 
    5558        super(ZAPostCodeField, self).__init__(r'^\d{4}$', 
    56             max_length=None, min_length=None, 
    57             error_message=_(u'Enter a valid South African postal code')) 
     59            max_length=None, min_length=None)