Changeset 6926 for django/trunk/django/contrib/localflavor/nl
- Timestamp:
- 12/17/07 02:05:27 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/localflavor/nl/forms.py
r6139 r6926 18 18 A Dutch postal code field. 19 19 """ 20 default_error_messages = { 21 'invalid': _('Enter a valid postal code'), 22 } 23 20 24 def clean(self, value): 21 25 super(NLZipCodeField, self).clean(value) 22 26 if value in EMPTY_VALUES: 23 27 return u'' 24 25 msg = _('Enter a valid postal code') 28 26 29 value = value.strip().upper().replace(' ', '') 27 30 if not pc_re.search(value): 28 raise ValidationError( msg)29 31 raise ValidationError(self.error_messages['invalid']) 32 30 33 if int(value[:4]) < 1000: 31 raise ValidationError( msg)32 34 raise ValidationError(self.error_messages['invalid']) 35 33 36 return u'%s %s' % (value[:4], value[4:]) 34 37 35 38 class NLProvinceSelect(Select): 36 39 """ 37 A Select widget that uses a list of provinces of the Netherlands as its 40 A Select widget that uses a list of provinces of the Netherlands as its 38 41 choices. 39 42 """ … … 46 49 A Dutch telephone number field. 47 50 """ 51 default_error_messages = { 52 'invalid': _('Enter a valid phone number'), 53 } 54 48 55 def clean(self, value): 49 56 super(NLPhoneNumberField, self).clean(value) 50 57 if value in EMPTY_VALUES: 51 58 return u'' 52 53 msg = _('Enter a valid phone number') 59 54 60 phone_nr = re.sub('[\-\s\(\)]', '', smart_unicode(value)) 55 61 56 62 if len(phone_nr) == 10 and numeric_re.search(phone_nr): 57 63 return value 58 64 59 65 if phone_nr[:3] == '+31' and len(phone_nr) == 12 and \ 60 66 numeric_re.search(phone_nr[3:]): 61 67 return value 62 63 raise ValidationError( msg)68 69 raise ValidationError(self.error_messages['invalid']) 64 70 65 71 class NLSoFiNumberField(Field): 66 72 """ 67 73 A Dutch social security number (SoFi/BSN) field. 68 74 69 75 http://nl.wikipedia.org/wiki/Sofinummer 70 76 """ 77 default_error_messages = { 78 'invalid': _('Enter a valid SoFi number'), 79 } 80 71 81 def clean(self, value): 72 82 super(NLSoFiNumberField, self).clean(value) 73 83 if value in EMPTY_VALUES: 74 84 return u'' 75 76 msg = _('Enter a valid SoFi number') 77 85 78 86 if not sofi_re.search(value): 79 raise ValidationError( msg)80 87 raise ValidationError(self.error_messages['invalid']) 88 81 89 if int(value) == 0: 82 raise ValidationError( msg)83 90 raise ValidationError(self.error_messages['invalid']) 91 84 92 checksum = 0 85 93 for i in range(9, 1, -1): 86 94 checksum += int(value[9-i]) * i 87 95 checksum -= int(value[-1]) 88 96 89 97 if checksum % 11 != 0: 90 raise ValidationError( msg)91 98 raise ValidationError(self.error_messages['invalid']) 99 92 100 return value
