Ticket #6637: 6637.diff

File 6637.diff, 3.7 KB (added by curtis, 17 years ago)

Change PhoneNumber from Int to Char field

  • django/oldforms/__init__.py

     
    972972
    973973class PhoneNumberField(TextField):
    974974    "A convenience FormField for validating phone numbers (e.g. '630-555-1234')"
    975     def __init__(self, field_name, is_required=False, validator_list=None):
     975    def __init__(self, field_name, max_length=None, is_required=False, validator_list=None):
    976976        if validator_list is None: validator_list = []
    977977        validator_list = [self.isValidPhone] + validator_list
    978978        TextField.__init__(self, field_name, length=12, max_length=12,
  • django/db/models/fields/__init__.py

     
    967967        defaults.update(kwargs)
    968968        return super(NullBooleanField, self).formfield(**defaults)
    969969
    970 class PhoneNumberField(IntegerField):
     970class PhoneNumberField(CharField):
     971   
     972    def __init__(self, *args, **kwargs):
     973        kwargs['max_length'] = kwargs.get('max_length', 15)
     974        CharField.__init__(self, *args, **kwargs)
     975       
    971976    def get_manipulator_field_objs(self):
    972977        return [oldforms.PhoneNumberField]
    973978
     
    981986        from django.contrib.localflavor.us.forms import USPhoneNumberField
    982987        defaults = {'form_class': USPhoneNumberField}
    983988        defaults.update(kwargs)
    984         return super(PhoneNumberField, self).formfield(**defaults)
     989        return super(CharField, self).formfield(**defaults)
    985990
    986991class PositiveIntegerField(IntegerField):
    987992    def get_manipulator_field_objs(self):
  • django/contrib/localflavor/us/forms.py

     
    3535            return u'%s-%s-%s' % (m.group(1), m.group(2), m.group(3))
    3636        raise ValidationError(self.error_messages['invalid'])
    3737
     38    def __init__(self, *args, **kwargs):
     39        super(USPhoneNumberField, self).__init__(*args, **kwargs)
     40       
    3841class USSocialSecurityNumberField(Field):
    3942    """
    4043    A United States Social Security number.
  • tests/regressiontests/model_fields/tests.py

     
    1 """
     1from django.db import models
     2
     3class PhoneNumber(models.Model):
     4    phone = models.PhoneNumberField(null=False, blank=True)
     5    description = models.CharField(max_length=20)
     6
     7    def __unicode__(self):
     8        return self.phone
     9
     10__test__ = {'API_TESTS': """   
    211>>> from django.db.models.fields import *
    312
    413# DecimalField
     
    1524Traceback (most recent call last):
    1625...
    1726ValidationError: [u'This value must be a decimal number.']
    18 """
     27
     28# Make sure that a blank phone number can be saved.
     29# See http://code.djangoproject.com/ticket/6637
     30>>> p = PhoneNumber()
     31>>> p.save()
     32>>> PhoneNumber.objects.all()
     33[<PhoneNumber: >]
     34>>> p = PhoneNumber()
     35>>> p.phone = "612-282-2573"
     36>>> p.description = "Fake Phone Number"
     37>>> p.save()
     38>>> PhoneNumber.objects.all()
     39[<PhoneNumber: >, <PhoneNumber: 612-282-2573>]
     40"""}
  • AUTHORS

     
    377377    ymasuda@ethercube.com
    378378    Jarek Zgoda <jarek.zgoda@gmail.com>
    379379    Cheng Zhang
     380    Curtis Thompson <curtis.thompson@gmail.com>
    380381
    381382A big THANK YOU goes to:
    382383
Back to Top