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
This commit is contained in:
parent
d48f530b0e
commit
0e88350893
|
@ -3,7 +3,7 @@ USA-specific Form helpers
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django.forms import ValidationError
|
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.encoding import smart_unicode
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
import re
|
import re
|
||||||
|
@ -20,7 +20,7 @@ class USZipCodeField(RegexField):
|
||||||
super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$',
|
super(USZipCodeField, self).__init__(r'^\d{5}(?:-\d{4})?$',
|
||||||
max_length=None, min_length=None, *args, **kwargs)
|
max_length=None, min_length=None, *args, **kwargs)
|
||||||
|
|
||||||
class USPhoneNumberField(Field):
|
class USPhoneNumberField(CharField):
|
||||||
default_error_messages = {
|
default_error_messages = {
|
||||||
'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.',
|
'invalid': u'Phone numbers must be in XXX-XXX-XXXX format.',
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.translation import ugettext_lazy as _
|
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
|
from django.contrib.localflavor.us.us_states import STATE_CHOICES
|
||||||
|
|
||||||
class USStateField(CharField):
|
class USStateField(CharField):
|
||||||
|
@ -12,22 +12,16 @@ class USStateField(CharField):
|
||||||
kwargs['max_length'] = 2
|
kwargs['max_length'] = 2
|
||||||
super(USStateField, self).__init__(*args, **kwargs)
|
super(USStateField, self).__init__(*args, **kwargs)
|
||||||
|
|
||||||
class PhoneNumberField(Field):
|
class PhoneNumberField(CharField):
|
||||||
|
|
||||||
description = _("Phone number")
|
description = _("Phone number")
|
||||||
|
|
||||||
def get_internal_type(self):
|
def __init__(self, *args, **kwargs):
|
||||||
return "PhoneNumberField"
|
kwargs['max_length'] = 20
|
||||||
|
super(PhoneNumberField, self).__init__(*args, **kwargs)
|
||||||
def db_type(self, connection):
|
|
||||||
if connection.settings_dict['ENGINE'] == 'django.db.backends.oracle':
|
|
||||||
return 'VARCHAR2(20)'
|
|
||||||
else:
|
|
||||||
return 'varchar(20)'
|
|
||||||
|
|
||||||
def formfield(self, **kwargs):
|
def formfield(self, **kwargs):
|
||||||
from django.contrib.localflavor.us.forms import USPhoneNumberField
|
from django.contrib.localflavor.us.forms import USPhoneNumberField
|
||||||
defaults = {'form_class': USPhoneNumberField}
|
defaults = {'form_class': USPhoneNumberField}
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
return super(PhoneNumberField, self).formfield(**defaults)
|
return super(PhoneNumberField, self).formfield(**defaults)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue