Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #20439 -- Started deprecation of IPAddressField

  • Loading branch information...
commit 1a63092981c685214ea189a14007da7bcc823c17 1 parent 8f51ba6
Erik Romijn authored aaugustin committed
2  django/db/models/fields/__init__.py
@@ -1312,6 +1312,8 @@ class IPAddressField(Field):
1312 1312
     description = _("IPv4 address")
1313 1313
 
1314 1314
     def __init__(self, *args, **kwargs):
  1315
+        warnings.warn("IPAddressField has been deprecated. Use GenericIPAddressField instead.",
  1316
+                      PendingDeprecationWarning)
1315 1317
         kwargs['max_length'] = 15
1316 1318
         Field.__init__(self, *args, **kwargs)
1317 1319
 
6  django/forms/fields.py
@@ -9,6 +9,7 @@
9 9
 import os
10 10
 import re
11 11
 import sys
  12
+import warnings
12 13
 from decimal import Decimal, DecimalException
13 14
 from io import BytesIO
14 15
 
@@ -1144,6 +1145,11 @@ def compress(self, data_list):
1144 1145
 class IPAddressField(CharField):
1145 1146
     default_validators = [validators.validate_ipv4_address]
1146 1147
 
  1148
+    def __init__(self, *args, **kwargs):
  1149
+        warnings.warn("IPAddressField has been deprecated. Use GenericIPAddressField instead.",
  1150
+                      PendingDeprecationWarning)
  1151
+        super(IPAddressField, self).__init__(*args, **kwargs)
  1152
+
1147 1153
     def to_python(self, value):
1148 1154
         if value in self.empty_values:
1149 1155
             return ''
2  docs/internals/deprecation.txt
@@ -436,6 +436,8 @@ these changes.
436 436
   :ref:`initial SQL data<initial-sql>` in ``myapp/models/sql/``. Move your
437 437
   custom SQL files to ``myapp/sql/``.
438 438
 
  439
+* The model and form ``IPAddressField`` will be removed.
  440
+
439 441
 * FastCGI support via the ``runfcgi`` management command will be
440 442
   removed. Please deploy your project using WSGI.
441 443
 
4  docs/ref/forms/fields.txt
@@ -657,6 +657,10 @@ For each field, we describe the default widget used if you don't specify
657 657
 
658 658
 .. class:: IPAddressField(**kwargs)
659 659
 
  660
+    .. deprecated:: 1.7
  661
+        This field has been deprecated in favour of
  662
+        :class:`~django.forms.GenericIPAddressField`.
  663
+
660 664
     * Default widget: :class:`TextInput`
661 665
     * Empty value: ``''`` (an empty string)
662 666
     * Normalizes to: A Unicode object.
4  docs/ref/models/fields.txt
@@ -849,6 +849,10 @@ An integer. The default form widget for this field is a
849 849
 
850 850
 .. class:: IPAddressField([**options])
851 851
 
  852
+.. deprecated:: 1.7
  853
+    This field has been deprecated in favour of
  854
+    :class:`~django.db.models.GenericIPAddressField`.
  855
+
852 856
 An IP address, in string format (e.g. "192.0.2.30"). The default form widget
853 857
 for this field is a :class:`~django.forms.TextInput`.
854 858
 
9  docs/releases/1.7.txt
@@ -529,3 +529,12 @@ to ``utils.py`` in an effort to unify all util and utils references:
529 529
 ``ModelAdmin.get_formsets`` has been deprecated in favor of the new
530 530
 :meth:`~django.contrib.admin.ModelAdmin.get_formsets_with_inlines`, in order to
531 531
 better handle the case of selecting showing inlines on a ``ModelAdmin``.
  532
+
  533
+``IPAddressField``
  534
+~~~~~~~~~~~~~~~~~~
  535
+
  536
+The :class:`django.db.models.IPAddressField` and
  537
+:class:`django.forms.IPAddressField` fields have been deprecated in favor of
  538
+:class:`django.db.models.GenericIPAddressField` and
  539
+:class:`django.forms.GenericIPAddressField`.
  540
+
5  tests/field_deconstruction/tests.py
... ...
@@ -1,3 +1,4 @@
  1
+import warnings
1 2
 from django.test import TestCase
2 3
 from django.db import models
3 4
 
@@ -173,7 +174,9 @@ def test_integer_field(self):
173 174
         self.assertEqual(kwargs, {})
174 175
 
175 176
     def test_ip_address_field(self):
176  
-        field = models.IPAddressField()
  177
+        with warnings.catch_warnings(record=True) as w:
  178
+            warnings.simplefilter("always")
  179
+            field = models.IPAddressField()
177 180
         name, path, args, kwargs = field.deconstruct()
178 181
         self.assertEqual(path, "django.db.models.IPAddressField")
179 182
         self.assertEqual(args, [])
6  tests/forms_tests/tests/test_error_messages.py
... ...
@@ -1,6 +1,8 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from __future__ import unicode_literals
3 3
 
  4
+import warnings
  5
+
4 6
 from django.core.files.uploadedfile import SimpleUploadedFile
5 7
 from django.forms import *
6 8
 from django.test import TestCase
@@ -192,7 +194,9 @@ def test_ipaddressfield(self):
192 194
             'required': 'REQUIRED',
193 195
             'invalid': 'INVALID IP ADDRESS',
194 196
         }
195  
-        f = IPAddressField(error_messages=e)
  197
+        with warnings.catch_warnings(record=True) as w:
  198
+            warnings.simplefilter("always")
  199
+            f = IPAddressField(error_messages=e)
196 200
         self.assertFormErrors(['REQUIRED'], f.clean, '')
197 201
         self.assertFormErrors(['INVALID IP ADDRESS'], f.clean, '127.0.0')
198 202
 
9  tests/forms_tests/tests/test_extra.py
@@ -2,6 +2,7 @@
2 2
 from __future__ import unicode_literals
3 3
 
4 4
 import datetime
  5
+import warnings
5 6
 
6 7
 from django.forms import *
7 8
 from django.forms.extras import SelectDateWidget
@@ -535,7 +536,9 @@ class ComplexFieldForm(Form):
535 536
         self.assertEqual(f.cleaned_data['field1'], 'some text,JP,2007-04-25 06:24:00')
536 537
 
537 538
     def test_ipaddress(self):
538  
-        f = IPAddressField()
  539
+        with warnings.catch_warnings(record=True) as w:
  540
+            warnings.simplefilter("always")
  541
+            f = IPAddressField()
539 542
         self.assertFormErrors(['This field is required.'], f.clean, '')
540 543
         self.assertFormErrors(['This field is required.'], f.clean, None)
541 544
         self.assertEqual(f.clean(' 127.0.0.1'), '127.0.0.1')
@@ -544,7 +547,9 @@ def test_ipaddress(self):
544 547
         self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '1.2.3.4.5')
545 548
         self.assertFormErrors(['Enter a valid IPv4 address.'], f.clean, '256.125.1.5')
546 549
 
547  
-        f = IPAddressField(required=False)
  550
+        with warnings.catch_warnings(record=True) as w:
  551
+            warnings.simplefilter("always")
  552
+            f = IPAddressField(required=False)
548 553
         self.assertEqual(f.clean(''), '')
549 554
         self.assertEqual(f.clean(None), '')
550 555
         self.assertEqual(f.clean(' 127.0.0.1'), '127.0.0.1')
5  tests/inspectdb/models.py
... ...
@@ -1,5 +1,6 @@
1 1
 # -*- encoding: utf-8 -*-
2 2
 from __future__ import unicode_literals
  3
+import warnings
3 4
 
4 5
 from django.db import models
5 6
 
@@ -49,7 +50,9 @@ class ColumnTypes(models.Model):
49 50
     file_path_field = models.FilePathField()
50 51
     float_field = models.FloatField()
51 52
     int_field = models.IntegerField()
52  
-    ip_address_field = models.IPAddressField()
  53
+    with warnings.catch_warnings(record=True) as w:
  54
+        warnings.simplefilter("always")
  55
+        ip_address_field = models.IPAddressField()
53 56
     gen_ip_adress_field = models.GenericIPAddressField(protocol="ipv4")
54 57
     pos_int_field = models.PositiveIntegerField()
55 58
     pos_small_int_field = models.PositiveSmallIntegerField()
5  tests/model_fields/models.py
... ...
@@ -1,5 +1,6 @@
1 1
 import os
2 2
 import tempfile
  3
+import warnings
3 4
 
4 5
 from django.core.exceptions import ImproperlyConfigured
5 6
 
@@ -85,7 +86,9 @@ class VerboseNameField(models.Model):
85 86
     # Don't want to depend on Pillow/PIL in this test
86 87
     #field_image = models.ImageField("verbose field")
87 88
     field12 = models.IntegerField("verbose field12")
88  
-    field13 = models.IPAddressField("verbose field13")
  89
+    with warnings.catch_warnings(record=True) as w:
  90
+        warnings.simplefilter("always")
  91
+        field13 = models.IPAddressField("verbose field13")
89 92
     field14 = models.GenericIPAddressField("verbose field14", protocol="ipv4")
90 93
     field15 = models.NullBooleanField("verbose field15")
91 94
     field16 = models.PositiveIntegerField("verbose field16")
9  tests/model_fields/tests.py
@@ -3,6 +3,7 @@
3 3
 import datetime
4 4
 from decimal import Decimal
5 5
 import unittest
  6
+import warnings
6 7
 
7 8
 from django import test
8 9
 from django import forms
@@ -603,9 +604,11 @@ def test_IntegerField(self):
603 604
 
604 605
     def test_IPAddressField(self):
605 606
         lazy_func = lazy(lambda: '127.0.0.1', six.text_type)
606  
-        self.assertIsInstance(
607  
-            IPAddressField().get_prep_value(lazy_func()),
608  
-            six.text_type)
  607
+        with warnings.catch_warnings(record=True) as w:
  608
+            warnings.simplefilter("always")
  609
+            self.assertIsInstance(
  610
+                IPAddressField().get_prep_value(lazy_func()),
  611
+                six.text_type)
609 612
 
610 613
     def test_GenericIPAddressField(self):
611 614
         lazy_func = lazy(lambda: '127.0.0.1', six.text_type)
9  tests/serializers_regress/models.py
@@ -4,6 +4,7 @@
4 4
 This class sets up a model for each model field type
5 5
 (except for image types, because of the Pillow/PIL dependency).
6 6
 """
  7
+import warnings
7 8
 
8 9
 from django.db import models
9 10
 from django.contrib.contenttypes import generic
@@ -52,7 +53,9 @@ class BigIntegerData(models.Model):
52 53
 #    data = models.ImageField(null=True)
53 54
 
54 55
 class IPAddressData(models.Model):
55  
-    data = models.IPAddressField(null=True)
  56
+    with warnings.catch_warnings(record=True) as w:
  57
+        warnings.simplefilter("always")
  58
+        data = models.IPAddressField(null=True)
56 59
 
57 60
 class GenericIPAddressData(models.Model):
58 61
     data = models.GenericIPAddressField(null=True)
@@ -199,7 +202,9 @@ class IntegerPKData(models.Model):
199 202
 #    data = models.ImageField(primary_key=True)
200 203
 
201 204
 class IPAddressPKData(models.Model):
202  
-    data = models.IPAddressField(primary_key=True)
  205
+    with warnings.catch_warnings(record=True) as w:
  206
+        warnings.simplefilter("always")
  207
+        data = models.IPAddressField(primary_key=True)
203 208
 
204 209
 class GenericIPAddressPKData(models.Model):
205 210
     data = models.GenericIPAddressField(primary_key=True)
5  tests/string_lookup/models.py
... ...
@@ -1,5 +1,6 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from __future__ import unicode_literals
  3
+import warnings
3 4
 
4 5
 from django.db import models
5 6
 from django.utils.encoding import python_2_unicode_compatible
@@ -49,7 +50,9 @@ def __str__(self):
49 50
 class Article(models.Model):
50 51
     name = models.CharField(max_length=50)
51 52
     text = models.TextField()
52  
-    submitted_from = models.IPAddressField(blank=True, null=True)
  53
+    with warnings.catch_warnings(record=True) as w:
  54
+        warnings.simplefilter("always")
  55
+        submitted_from = models.IPAddressField(blank=True, null=True)
53 56
 
54 57
     def __str__(self):
55 58
         return "Article %s" % self.name

0 notes on commit 1a63092

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