PageRenderTime 102ms CodeModel.GetById 60ms app.highlight 4ms RepoModel.GetById 37ms app.codeStats 0ms

/django/contrib/localflavor/us/models.py

https://code.google.com/p/mango-py/
Python | 37 lines | 27 code | 10 blank | 0 comment | 0 complexity | a1d67928340d351fd5d48421603503df MD5 | raw file
 1from django.conf import settings
 2from django.utils.translation import ugettext_lazy as _
 3from django.db.models.fields import CharField
 4from django.contrib.localflavor.us.us_states import STATE_CHOICES
 5from django.contrib.localflavor.us.us_states import USPS_CHOICES
 6
 7class USStateField(CharField):
 8
 9    description = _("U.S. state (two uppercase letters)")
10
11    def __init__(self, *args, **kwargs):
12        kwargs['choices'] = STATE_CHOICES
13        kwargs['max_length'] = 2
14        super(USStateField, self).__init__(*args, **kwargs)
15
16class USPostalCodeField(CharField):
17
18    description = _("U.S. postal code (two uppercase letters)")
19
20    def __init__(self, *args, **kwargs):
21        kwargs['choices'] = USPS_CHOICES
22        kwargs['max_length'] = 2
23        super(USPostalCodeField, self).__init__(*args, **kwargs)
24
25class PhoneNumberField(CharField):
26
27    description = _("Phone number")
28
29    def __init__(self, *args, **kwargs):
30        kwargs['max_length'] = 20
31        super(PhoneNumberField, self).__init__(*args, **kwargs)
32
33    def formfield(self, **kwargs):
34        from django.contrib.localflavor.us.forms import USPhoneNumberField
35        defaults = {'form_class': USPhoneNumberField}
36        defaults.update(kwargs)
37        return super(PhoneNumberField, self).formfield(**defaults)