From 43c5d35315299330aaca1e2aab6fd2548eff7fcb Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Mon, 21 Nov 2011 12:42:09 +0000 Subject: [PATCH] Fixed #17274 -- Accepted TIME_ZONE = None when USE_TZ = True. Thanks pressureman for the report. This problem only occured when pytz is installed. It's still strongly recommended to define the correct time zone in TIME_ZONE in order to use pytz' implementation and not the approximation based on system time. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17134 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/timezone.py | 6 ++++-- tests/modeltests/timezones/tests.py | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/django/utils/timezone.py b/django/utils/timezone.py index 9e78134d2a..16e65fc62d 100644 --- a/django/utils/timezone.py +++ b/django/utils/timezone.py @@ -102,8 +102,10 @@ def get_default_timezone(): """ global _localtime if _localtime is None: - tz = settings.TIME_ZONE - _localtime = pytz.timezone(tz) if pytz else LocalTimezone() + if isinstance(settings.TIME_ZONE, basestring) and pytz is not None: + _localtime = pytz.timezone(settings.TIME_ZONE) + else: + _localtime = LocalTimezone() return _localtime # This function exists for consistency with get_current_timezone_name diff --git a/tests/modeltests/timezones/tests.py b/tests/modeltests/timezones/tests.py index a2f4ad2029..53b14045ab 100644 --- a/tests/modeltests/timezones/tests.py +++ b/tests/modeltests/timezones/tests.py @@ -774,6 +774,17 @@ class TemplateTests(BaseDateTimeTests): with timezone.override(ICT): self.assertEqual(tpl.render(ctx), "2011-09-01 at 20:20:20") + def test_localtime_with_time_zone_setting_set_to_none(self): + # Regression for #17274 + tpl = Template("{% load tz %}{{ dt }}") + ctx = Context({'dt': datetime.datetime(2011, 9, 1, 12, 20, 30, tzinfo=EAT)}) + + timezone._localtime = None + with self.settings(TIME_ZONE=None): + # the actual value depends on the system time zone of the host + self.assertTrue(tpl.render(ctx).startswith("2011")) + timezone._localtime = None + TemplateTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(TemplateTests) #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)