| Home | Trees | Indices | Help |
|
|---|
|
|
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
14 """Australian post code field."""
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
22 """Australian phone number field."""
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
37 """
38 A Select widget that uses a list of Australian states/territories as its
39 choices.
40 """
42 from au_states import STATE_CHOICES
43 super(AUStateSelect, self).__init__(attrs, choices=STATE_CHOICES)
44
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Fri Dec 14 15:24:18 2007 | http://epydoc.sourceforge.net |