Ticket #5871: localflavor.nl.error_mesages.diff

File localflavor.nl.error_mesages.diff, 3.3 KB (added by smn, 17 years ago)

diff with changes in code & test

  • django/contrib/localflavor/nl/forms.py

     
    2222        if value in EMPTY_VALUES:
    2323            return u''
    2424       
    25         msg = _('Enter a valid postal code')
    2625        value = value.strip().upper().replace(' ', '')
    2726        if not pc_re.search(value):
    28             raise ValidationError(msg)
     27            raise ValidationError(self.error_messages['required'])
    2928       
    3029        if int(value[:4]) < 1000:
    31             raise ValidationError(msg)
     30            raise ValidationError(self.error_messages['required'])
    3231       
    3332        return u'%s %s' % (value[:4], value[4:])
    3433
     
    5049        if value in EMPTY_VALUES:
    5150            return u''
    5251       
    53         msg = _('Enter a valid phone number')
    5452        phone_nr = re.sub('[\-\s\(\)]', '', smart_unicode(value))
    5553       
    5654        if len(phone_nr) == 10 and numeric_re.search(phone_nr):
     
    6058           numeric_re.search(phone_nr[3:]):
    6159            return value
    6260       
    63         raise ValidationError(msg)
     61        raise ValidationError(self.error_messages['required'])
    6462
    6563class NLSoFiNumberField(Field):
    6664    """
     
    7371        if value in EMPTY_VALUES:
    7472            return u''
    7573       
    76         msg = _('Enter a valid SoFi number')
    77        
    7874        if not sofi_re.search(value):
    79             raise ValidationError(msg)
     75            raise ValidationError(self.error_messages['required'])
    8076       
    8177        if int(value) == 0:
    82             raise ValidationError(msg)
     78            raise ValidationError(self.error_messages['required'])
    8379       
    8480        checksum = 0
    8581        for i in range(9, 1, -1):
     
    8783        checksum -= int(value[-1])
    8884       
    8985        if checksum % 11 != 0:
    90             raise ValidationError(msg)
     86            raise ValidationError(self.error_messages['required'])
    9187       
    9288        return value
  • tests/regressiontests/forms/localflavor/nl.py

     
    55# NLPhoneNumberField ########################################################
    66
    77>>> from django.contrib.localflavor.nl.forms import NLPhoneNumberField
    8 >>> f = NLPhoneNumberField(required=False)
     8>>> f = NLPhoneNumberField(required=False, error_messages={'required':'Enter a valid phone number'})
    99>>> f.clean('')
    1010u''
    1111>>> f.clean('012-3456789')
     
    2424# NLZipCodeField ############################################################
    2525
    2626>>> from django.contrib.localflavor.nl.forms import NLZipCodeField
    27 >>> f = NLZipCodeField(required=False)
     27>>> f = NLZipCodeField(required=False, error_messages={'required':'Enter a valid postal code'})
    2828>>> f.clean('')
    2929u''
    3030>>> f.clean('1234ab')
     
    4545# NLSoFiNumberField #########################################################
    4646
    4747>>> from django.contrib.localflavor.nl.forms import NLSoFiNumberField
    48 >>> f = NLSoFiNumberField(required=False)
     48>>> f = NLSoFiNumberField(required=False, error_messages={'required':'Enter a valid SoFi number'})
    4949>>> f.clean('')
    5050u''
    5151>>> f.clean('123456782')
Back to Top