From 306d34873cff2722e209d8c6058f13eac1532a7b Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 1 Sep 2012 18:32:27 +0200 Subject: [PATCH] Fixed #18212 -- Standardized arguments of GenericIPAddressField Unlike other model fields, the newly introduced (1.4) GenericIPAddressField did not accept verbose_name and name as the first positional arguments. This commit fixes it. Thanks Dan McGee for the report and the patch. --- django/db/models/fields/__init__.py | 5 ++-- docs/releases/1.4.2.txt | 14 ++++++++++ docs/releases/index.txt | 1 + tests/modeltests/validation/models.py | 2 ++ tests/regressiontests/model_fields/models.py | 27 ++++++++++++++++++++ tests/regressiontests/model_fields/tests.py | 10 +++++++- 6 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 docs/releases/1.4.2.txt diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index d07851bbf5..58ae3413f3 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -1047,13 +1047,14 @@ class GenericIPAddressField(Field): description = _("IP address") default_error_messages = {} - def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs): + def __init__(self, verbose_name=None, name=None, protocol='both', + unpack_ipv4=False, *args, **kwargs): self.unpack_ipv4 = unpack_ipv4 self.default_validators, invalid_error_message = \ validators.ip_address_validators(protocol, unpack_ipv4) self.default_error_messages['invalid'] = invalid_error_message kwargs['max_length'] = 39 - Field.__init__(self, *args, **kwargs) + Field.__init__(self, verbose_name, name, *args, **kwargs) def get_internal_type(self): return "GenericIPAddressField" diff --git a/docs/releases/1.4.2.txt b/docs/releases/1.4.2.txt new file mode 100644 index 0000000000..6f2e9aca2e --- /dev/null +++ b/docs/releases/1.4.2.txt @@ -0,0 +1,14 @@ +========================== +Django 1.4.2 release notes +========================== + +*TO BE RELEASED* + +This is the second security release in the Django 1.4 series. + +Backwards incompatible changes +============================== + +* The newly introduced :class:`~django.db.models.GenericIPAddressField` + constructor arguments have been adapted to match those of all other model + fields. The first two keyword arguments are now verbose_name and name. diff --git a/docs/releases/index.txt b/docs/releases/index.txt index 75cdbbf90d..fa55a4d206 100644 --- a/docs/releases/index.txt +++ b/docs/releases/index.txt @@ -27,6 +27,7 @@ Final releases .. toctree:: :maxdepth: 1 + .. 1.4.2 (uncomment on release) 1.4.1 1.4 diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py index dcd9ced52c..db083290fb 100644 --- a/tests/modeltests/validation/models.py +++ b/tests/modeltests/validation/models.py @@ -91,6 +91,8 @@ class GenericIPAddressTestModel(models.Model): generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True) v4_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv4") v6_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv6") + ip_verbose_name = models.GenericIPAddressField("IP Address Verbose", + blank=True, null=True) class GenericIPAddrUnpackUniqueTest(models.Model): generic_v4unpack_ip = models.GenericIPAddressField(blank=True, unique=True, unpack_ipv4=True) diff --git a/tests/regressiontests/model_fields/models.py b/tests/regressiontests/model_fields/models.py index 4dcfb17bb3..d9c123fb39 100644 --- a/tests/regressiontests/model_fields/models.py +++ b/tests/regressiontests/model_fields/models.py @@ -69,6 +69,33 @@ class BooleanModel(models.Model): class RenamedField(models.Model): modelname = models.IntegerField(name="fieldname", choices=((1,'One'),)) +class VerboseNameField(models.Model): + id = models.AutoField("verbose pk", primary_key=True) + field1 = models.BigIntegerField("verbose field1") + field2 = models.BooleanField("verbose field2") + field3 = models.CharField("verbose field3", max_length=10) + field4 = models.CommaSeparatedIntegerField("verbose field4", max_length=99) + field5 = models.DateField("verbose field5") + field6 = models.DateTimeField("verbose field6") + field7 = models.DecimalField("verbose field7", max_digits=6, decimal_places=1) + field8 = models.EmailField("verbose field8") + field9 = models.FileField("verbose field9", upload_to="unused") + field10 = models.FilePathField("verbose field10") + field11 = models.FloatField("verbose field11") + # Don't want to depend on PIL in this test + #field_image = models.ImageField("verbose field") + field12 = models.IntegerField("verbose field12") + field13 = models.IPAddressField("verbose field13") + field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4") + field15 = models.NullBooleanField("verbose field15") + field16 = models.PositiveIntegerField("verbose field16") + field17 = models.PositiveSmallIntegerField("verbose field17") + field18 = models.SlugField("verbose field18") + field19 = models.SmallIntegerField("verbose field19") + field20 = models.TextField("verbose field20") + field21 = models.TimeField("verbose field21") + field22 = models.URLField("verbose field22") + # This model isn't used in any test, just here to ensure it validates successfully. # See ticket #16570. class DecimalLessThanOne(models.Model): diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py index 7d6071accc..526aca4f98 100644 --- a/tests/regressiontests/model_fields/tests.py +++ b/tests/regressiontests/model_fields/tests.py @@ -12,7 +12,7 @@ from django.utils import six from django.utils import unittest from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post, - NullBooleanModel, BooleanModel, Document, RenamedField) + NullBooleanModel, BooleanModel, Document, RenamedField, VerboseNameField) from .imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests, TwoImageFieldTests, ImageFieldNoDimensionsTests, @@ -64,6 +64,14 @@ class BasicFieldTests(test.TestCase): self.assertTrue(hasattr(instance, 'get_fieldname_display')) self.assertFalse(hasattr(instance, 'get_modelname_display')) + def test_field_verbose_name(self): + m = VerboseNameField + for i in range(1, 23): + self.assertEqual(m._meta.get_field('field%d' % i).verbose_name, + 'verbose field%d' % i) + + self.assertEqual(m._meta.get_field('id').verbose_name, 'verbose pk') + class DecimalFieldTests(test.TestCase): def test_to_python(self): f = models.DecimalField(max_digits=4, decimal_places=2)