Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #8898 -- Obsoleted SplitDateTimeWidget usage with DateTimeField

Thanks Tim Graham for the review.
  • Loading branch information...
commit 0179852d7faf461d55cf3ae69393abb3f3cd2910 1 parent 1e9e735
Claude Paroz authored December 04, 2013
4  django/forms/fields.py
@@ -486,6 +486,10 @@ def to_python(self, value):
486 486
         if isinstance(value, list):
487 487
             # Input comes from a SplitDateTimeWidget, for example. So, it's two
488 488
             # components: date and time.
  489
+            warnings.warn(
  490
+                'Using SplitDateTimeWidget with DateTimeField is deprecated. '
  491
+                'Use SplitDateTimeField instead.',
  492
+                PendingDeprecationWarning, stacklevel=2)
489 493
             if len(value) != 2:
490 494
                 raise ValidationError(self.error_messages['invalid'], code='invalid')
491 495
             if value[0] in self.empty_values and value[1] in self.empty_values:
3  docs/internals/deprecation.txt
@@ -215,6 +215,9 @@ these changes.
215 215
 
216 216
 * ``django.forms.get_declared_fields`` will be removed.
217 217
 
  218
+* The ability to use a ``SplitDateTimeWidget`` with ``DateTimeField`` will be
  219
+  removed.
  220
+
218 221
 * The ``WSGIRequest.REQUEST`` property will be removed.
219 222
 
220 223
 * The class ``django.utils.datastructures.MergeDict`` will be removed.
6  docs/ref/forms/fields.txt
@@ -458,6 +458,12 @@ For each field, we describe the default widget used if you don't specify
458 458
 
459 459
     See also :ref:`format localization <format-localization>`.
460 460
 
  461
+    .. deprecated:: 1.7
  462
+
  463
+        The ability to use :class:`SplitDateTimeWidget` with ``DateTimeField``
  464
+        has been deprecated and will be removed in Django 1.9. Use
  465
+        :class:`SplitDateTimeField` instead.
  466
+
461 467
 ``DecimalField``
462 468
 ~~~~~~~~~~~~~~~~
463 469
 
7  docs/releases/1.7.txt
@@ -1063,3 +1063,10 @@ the arguments may have been evaluated at query time.
1063 1063
 
1064 1064
 The ``ADMIN_FOR`` feature, part of the admindocs, has been removed. You can
1065 1065
 remove the setting from your configuration at your convenience.
  1066
+
  1067
+``SplitDateTimeWidget`` with ``DateTimeField``
  1068
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1069
+
  1070
+``SplitDateTimeWidget`` support in :class:`~django.forms.DateTimeField` is
  1071
+deprecated, use ``SplitDateTimeWidget`` with
  1072
+:class:`~django.forms.SplitDateTimeField` instead.
21  tests/forms_tests/tests/test_widgets.py
@@ -3,6 +3,7 @@
3 3
 
4 4
 import copy
5 5
 import datetime
  6
+import warnings
6 7
 
7 8
 from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
8 9
 from django.core.files.uploadedfile import SimpleUploadedFile
@@ -1092,18 +1093,22 @@ def test_13390(self):
1092 1093
         class SplitDateForm(Form):
1093 1094
             field = DateTimeField(widget=SplitDateTimeWidget, required=False)
1094 1095
 
1095  
-        form = SplitDateForm({'field': ''})
1096  
-        self.assertTrue(form.is_valid())
1097  
-        form = SplitDateForm({'field': ['', '']})
1098  
-        self.assertTrue(form.is_valid())
  1096
+        with warnings.catch_warnings():
  1097
+            warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
  1098
+            form = SplitDateForm({'field': ''})
  1099
+            self.assertTrue(form.is_valid())
  1100
+            form = SplitDateForm({'field': ['', '']})
  1101
+            self.assertTrue(form.is_valid())
1099 1102
 
1100 1103
         class SplitDateRequiredForm(Form):
1101 1104
             field = DateTimeField(widget=SplitDateTimeWidget, required=True)
1102 1105
 
1103  
-        form = SplitDateRequiredForm({'field': ''})
1104  
-        self.assertFalse(form.is_valid())
1105  
-        form = SplitDateRequiredForm({'field': ['', '']})
1106  
-        self.assertFalse(form.is_valid())
  1106
+        with warnings.catch_warnings():
  1107
+            warnings.filterwarnings("ignore", category=PendingDeprecationWarning)
  1108
+            form = SplitDateRequiredForm({'field': ''})
  1109
+            self.assertFalse(form.is_valid())
  1110
+            form = SplitDateRequiredForm({'field': ['', '']})
  1111
+            self.assertFalse(form.is_valid())
1107 1112
 
1108 1113
 
1109 1114
 class LiveWidgetTests(AdminSeleniumWebDriverTestCase):

0 notes on commit 0179852

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