From 0e883508936fc5d8e499e702a62413440fa66f0b Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 1 Jan 2010 21:36:08 +0000 Subject: [PATCH] Fixed #12474 - Removing SQL specific bits from USPhoneNumberField. Patch from Alex Gaynor. git-svn-id: http://code.djangoproject.com/svn/django/trunk@12049 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/localflavor/us/forms.py | 4 ++-- django/contrib/localflavor/us/models.py | 16 +++++----------- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/django/contrib/localflavor/us/forms.py b/django/contrib/localflavor/us/forms.py index a744edce74..5b24cde581 100644 --- a/django/contrib/localflavor/us/forms.py +++ b/django/contrib/localflavor/us/forms.py @@ -3,7 +3,7 @@ USA-specific Form helpers """ from django.forms import ValidationError -from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES +from django.forms.fields import Field, RegexField, Select, EMPTY_VALUES, CharField from django.utils.encoding import smart_unicode from django.utils.translation import ugettext_lazy as _ import re @@ -20,7 +20,7 @@ class USZipCodeField(RegexField): super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$', max_length=None, min_length=None, *args, **kwargs) -class USPhoneNumberField(Field): +class USPhoneNumberField(CharField): default_error_messages = { 'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.', } diff --git a/django/contrib/localflavor/us/models.py b/django/contrib/localflavor/us/models.py index 4cb6e6851e..1f78e4504a 100644 --- a/django/contrib/localflavor/us/models.py +++ b/django/contrib/localflavor/us/models.py @@ -1,6 +1,6 @@ from django.conf import settings from django.utils.translation import ugettext_lazy as _ -from django.db.models.fields import Field, CharField +from django.db.models.fields import CharField from django.contrib.localflavor.us.us_states import STATE_CHOICES class USStateField(CharField): @@ -12,22 +12,16 @@ class USStateField(CharField): kwargs['max_length'] = 2 super(USStateField, self).__init__(*args, **kwargs) -class PhoneNumberField(Field): +class PhoneNumberField(CharField): description = _("Phone number") - def get_internal_type(self): - return "PhoneNumberField" - - def db_type(self, connection): - if connection.settings_dict['ENGINE'] == 'django.db.backends.oracle': - return 'VARCHAR2(20)' - else: - return 'varchar(20)' + def __init__(self, *args, **kwargs): + kwargs['max_length'] = 20 + super(PhoneNumberField, self).__init__(*args, **kwargs) def formfield(self, **kwargs): from django.contrib.localflavor.us.forms import USPhoneNumberField defaults = {'form_class': USPhoneNumberField} defaults.update(kwargs) return super(PhoneNumberField, self).formfield(**defaults) -