PageRenderTime 41ms CodeModel.GetById 23ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause
  1. from django.conf import settings
  2. from django.utils.translation import ugettext_lazy as _
  3. from django.db.models.fields import CharField
  4. from django.contrib.localflavor.us.us_states import STATE_CHOICES
  5. from django.contrib.localflavor.us.us_states import USPS_CHOICES
  6. class USStateField(CharField):
  7. description = _("U.S. state (two uppercase letters)")
  8. def __init__(self, *args, **kwargs):
  9. kwargs['choices'] = STATE_CHOICES
  10. kwargs['max_length'] = 2
  11. super(USStateField, self).__init__(*args, **kwargs)
  12. class USPostalCodeField(CharField):
  13. description = _("U.S. postal code (two uppercase letters)")
  14. def __init__(self, *args, **kwargs):
  15. kwargs['choices'] = USPS_CHOICES
  16. kwargs['max_length'] = 2
  17. super(USPostalCodeField, self).__init__(*args, **kwargs)
  18. class PhoneNumberField(CharField):
  19. description = _("Phone number")
  20. def __init__(self, *args, **kwargs):
  21. kwargs['max_length'] = 20
  22. super(PhoneNumberField, self).__init__(*args, **kwargs)
  23. def formfield(self, **kwargs):
  24. from django.contrib.localflavor.us.forms import USPhoneNumberField
  25. defaults = {'form_class': USPhoneNumberField}
  26. defaults.update(kwargs)
  27. return super(PhoneNumberField, self).formfield(**defaults)