Package django :: Package contrib :: Package localflavor :: Package au :: Module forms
[hide private]
[frames] | no frames]

Source Code for Module django.contrib.localflavor.au.forms

 1  """ 
 2  Australian-specific Form helpers 
 3  """ 
 4   
 5  from django.newforms import ValidationError 
 6  from django.newforms.fields import Field, RegexField, Select, EMPTY_VALUES 
 7  from django.newforms.util import smart_unicode 
 8  from django.utils.translation import ugettext 
 9  import re 
10   
11  PHONE_DIGITS_RE = re.compile(r'^(\d{10})$') 
12   
13 -class AUPostCodeField(RegexField):
14 """Australian post code field."""
15 - def __init__(self, *args, **kwargs):
16 super(AUPostCodeField, self).__init__(r'^\d{4}$', 17 max_length=None, min_length=None, 18 error_message=ugettext('Enter a 4 digit post code.'), 19 *args, **kwargs)
20
21 -class AUPhoneNumberField(Field):
22 """Australian phone number field."""
23 - def clean(self, value):
24 """ 25 Validate a phone number. Strips parentheses, whitespace and hyphens. 26 """ 27 super(AUPhoneNumberField, self).clean(value) 28 if value in EMPTY_VALUES: 29 return u'' 30 value = re.sub('(\(|\)|\s+|-)', '', smart_unicode(value)) 31 phone_match = PHONE_DIGITS_RE.search(value) 32 if phone_match: 33 return u'%s' % phone_match.group(1) 34 raise ValidationError(u'Phone numbers must contain 10 digits.')
35
36 -class AUStateSelect(Select):
37 """ 38 A Select widget that uses a list of Australian states/territories as its 39 choices. 40 """
41 - def __init__(self, attrs=None):
44