From 614bec41b5306b32b8de20d66f047ff8d6f35256 Mon Sep 17 00:00:00 2001 From: Villiers Strauss Date: Fri, 22 May 2015 15:54:31 +0200 Subject: [PATCH] Fixed #24841 -- Made BaseRangeField.prepare_value() call base_field's prepare_value() --- django/contrib/postgres/forms/ranges.py | 11 +++++++++-- docs/releases/1.8.3.txt | 3 ++- tests/postgres_tests/test_ranges.py | 10 +++++++++- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/django/contrib/postgres/forms/ranges.py b/django/contrib/postgres/forms/ranges.py index cab22676857..75e5691d833 100644 --- a/django/contrib/postgres/forms/ranges.py +++ b/django/contrib/postgres/forms/ranges.py @@ -22,10 +22,17 @@ class BaseRangeField(forms.MultiValueField): super(BaseRangeField, self).__init__(**kwargs) def prepare_value(self, value): + lower_base, upper_base = self.fields if isinstance(value, self.range_type): - return [value.lower, value.upper] + return [ + lower_base.prepare_value(value.lower), + upper_base.prepare_value(value.upper), + ] if value is None: - return [None, None] + return [ + lower_base.prepare_value(None), + upper_base.prepare_value(None), + ] return value def compress(self, values): diff --git a/docs/releases/1.8.3.txt b/docs/releases/1.8.3.txt index ed293156c28..a8a649cdf01 100644 --- a/docs/releases/1.8.3.txt +++ b/docs/releases/1.8.3.txt @@ -9,4 +9,5 @@ Django 1.8.3 fixes several bugs in 1.8.2. Bugfixes ======== -* ... +* Fixed ``BaseRangeField.prepare_value()`` to use each ``base_field``’s + ``prepare_value()`` method (:ticket:`24841`). diff --git a/tests/postgres_tests/test_ranges.py b/tests/postgres_tests/test_ranges.py index cab7263af2a..5ec6dae27b6 100644 --- a/tests/postgres_tests/test_ranges.py +++ b/tests/postgres_tests/test_ranges.py @@ -5,7 +5,7 @@ import unittest from django import forms from django.core import exceptions, serializers from django.db import connection -from django.test import TestCase +from django.test import TestCase, override_settings from django.utils import timezone from . import PostgresSQLTestCase @@ -474,6 +474,14 @@ class TestFormField(PostgresSQLTestCase): value = field.clean(['2013-04-09 11:45', '']) self.assertEqual(value, DateTimeTZRange(datetime.datetime(2013, 4, 9, 11, 45), None)) + @override_settings(USE_TZ=True, TIME_ZONE='Africa/Johannesburg') + def test_datetime_prepare_value(self): + field = pg_forms.DateTimeRangeField() + value = field.prepare_value( + DateTimeTZRange(datetime.datetime(2015, 5, 22, 16, 6, 33, tzinfo=timezone.utc), None) + ) + self.assertEqual(value, [datetime.datetime(2015, 5, 22, 18, 6, 33), None]) + def test_model_field_formfield_integer(self): model_field = pg_fields.IntegerRangeField() form_field = model_field.formfield()