Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit 306d34873cff2722e209d8c6058f13eac1532a7b 1 parent 74c025d
Claude Paroz authored September 01, 2012
5  django/db/models/fields/__init__.py
@@ -1047,13 +1047,14 @@ class GenericIPAddressField(Field):
1047 1047
     description = _("IP address")
1048 1048
     default_error_messages = {}
1049 1049
 
1050  
-    def __init__(self, protocol='both', unpack_ipv4=False, *args, **kwargs):
  1050
+    def __init__(self, verbose_name=None, name=None, protocol='both',
  1051
+                 unpack_ipv4=False, *args, **kwargs):
1051 1052
         self.unpack_ipv4 = unpack_ipv4
1052 1053
         self.default_validators, invalid_error_message = \
1053 1054
             validators.ip_address_validators(protocol, unpack_ipv4)
1054 1055
         self.default_error_messages['invalid'] = invalid_error_message
1055 1056
         kwargs['max_length'] = 39
1056  
-        Field.__init__(self, *args, **kwargs)
  1057
+        Field.__init__(self, verbose_name, name, *args, **kwargs)
1057 1058
 
1058 1059
     def get_internal_type(self):
1059 1060
         return "GenericIPAddressField"
14  docs/releases/1.4.2.txt
... ...
@@ -0,0 +1,14 @@
  1
+==========================
  2
+Django 1.4.2 release notes
  3
+==========================
  4
+
  5
+*TO BE RELEASED*
  6
+
  7
+This is the second security release in the Django 1.4 series.
  8
+
  9
+Backwards incompatible changes
  10
+==============================
  11
+
  12
+* The newly introduced :class:`~django.db.models.GenericIPAddressField`
  13
+  constructor arguments have been adapted to match those of all other model
  14
+  fields. The first two keyword arguments are now verbose_name and name.
1  docs/releases/index.txt
@@ -27,6 +27,7 @@ Final releases
27 27
 .. toctree::
28 28
    :maxdepth: 1
29 29
 
  30
+   .. 1.4.2 (uncomment on release)
30 31
    1.4.1
31 32
    1.4
32 33
 
2  tests/modeltests/validation/models.py
@@ -91,6 +91,8 @@ class GenericIPAddressTestModel(models.Model):
91 91
     generic_ip = models.GenericIPAddressField(blank=True, null=True, unique=True)
92 92
     v4_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv4")
93 93
     v6_ip = models.GenericIPAddressField(blank=True, null=True, protocol="ipv6")
  94
+    ip_verbose_name = models.GenericIPAddressField("IP Address Verbose",
  95
+            blank=True, null=True)
94 96
 
95 97
 class GenericIPAddrUnpackUniqueTest(models.Model):
96 98
     generic_v4unpack_ip = models.GenericIPAddressField(blank=True, unique=True, unpack_ipv4=True)
27  tests/regressiontests/model_fields/models.py
@@ -69,6 +69,33 @@ class BooleanModel(models.Model):
69 69
 class RenamedField(models.Model):
70 70
     modelname = models.IntegerField(name="fieldname", choices=((1,'One'),))
71 71
 
  72
+class VerboseNameField(models.Model):
  73
+    id = models.AutoField("verbose pk", primary_key=True)
  74
+    field1 = models.BigIntegerField("verbose field1")
  75
+    field2 = models.BooleanField("verbose field2")
  76
+    field3 = models.CharField("verbose field3", max_length=10)
  77
+    field4 = models.CommaSeparatedIntegerField("verbose field4", max_length=99)
  78
+    field5 = models.DateField("verbose field5")
  79
+    field6 = models.DateTimeField("verbose field6")
  80
+    field7 = models.DecimalField("verbose field7", max_digits=6, decimal_places=1)
  81
+    field8 = models.EmailField("verbose field8")
  82
+    field9 = models.FileField("verbose field9", upload_to="unused")
  83
+    field10 = models.FilePathField("verbose field10")
  84
+    field11 = models.FloatField("verbose field11")
  85
+    # Don't want to depend on PIL in this test
  86
+    #field_image = models.ImageField("verbose field")
  87
+    field12 = models.IntegerField("verbose field12")
  88
+    field13 = models.IPAddressField("verbose field13")
  89
+    field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4")
  90
+    field15 = models.NullBooleanField("verbose field15")
  91
+    field16 = models.PositiveIntegerField("verbose field16")
  92
+    field17 = models.PositiveSmallIntegerField("verbose field17")
  93
+    field18 = models.SlugField("verbose field18")
  94
+    field19 = models.SmallIntegerField("verbose field19")
  95
+    field20 = models.TextField("verbose field20")
  96
+    field21 = models.TimeField("verbose field21")
  97
+    field22 = models.URLField("verbose field22")
  98
+
72 99
 # This model isn't used in any test, just here to ensure it validates successfully.
73 100
 # See ticket #16570.
74 101
 class DecimalLessThanOne(models.Model):
10  tests/regressiontests/model_fields/tests.py
@@ -12,7 +12,7 @@
12 12
 from django.utils import unittest
13 13
 
14 14
 from .models import (Foo, Bar, Whiz, BigD, BigS, Image, BigInt, Post,
15  
-    NullBooleanModel, BooleanModel, Document, RenamedField)
  15
+    NullBooleanModel, BooleanModel, Document, RenamedField, VerboseNameField)
16 16
 
17 17
 from .imagefield import (ImageFieldTests, ImageFieldTwoDimensionsTests,
18 18
     TwoImageFieldTests, ImageFieldNoDimensionsTests,
@@ -64,6 +64,14 @@ def test_field_name(self):
64 64
         self.assertTrue(hasattr(instance, 'get_fieldname_display'))
65 65
         self.assertFalse(hasattr(instance, 'get_modelname_display'))
66 66
 
  67
+    def test_field_verbose_name(self):
  68
+        m = VerboseNameField
  69
+        for i in range(1, 23):
  70
+            self.assertEqual(m._meta.get_field('field%d' % i).verbose_name,
  71
+                    'verbose field%d' % i)
  72
+
  73
+        self.assertEqual(m._meta.get_field('id').verbose_name, 'verbose pk')
  74
+
67 75
 class DecimalFieldTests(test.TestCase):
68 76
     def test_to_python(self):
69 77
         f = models.DecimalField(max_digits=4, decimal_places=2)

0 notes on commit 306d348

Please sign in to comment.
Something went wrong with that request. Please try again.