Author: aaugustin
Date: 2011-12-04 14:11:12 -0800 (Sun, 04 Dec 2011)
New Revision: 17169
Modified:
django/trunk/django/template/defaulttags.py
django/trunk/tests/modeltests/timezones/tests.py
Log:
Fixed #17343 -- Changed the {% now %} tag to use the current time zone when
time zone support is enabled. Thanks oinopion for the report.
Modified: django/trunk/django/template/defaulttags.py
===================================================================
--- django/trunk/django/template/defaulttags.py 2011-12-03 21:17:41 UTC (rev
17168)
+++ django/trunk/django/template/defaulttags.py 2011-12-04 22:11:12 UTC (rev
17169)
@@ -15,6 +15,7 @@
from django.template.defaultfilters import date
from django.utils.encoding import smart_str, smart_unicode
from django.utils.safestring import mark_safe
+from django.utils import timezone
register = Library()
@@ -343,7 +344,8 @@
self.format_string = format_string
def render(self, context):
- return date(datetime.now(), self.format_string)
+ tzinfo = timezone.get_current_timezone() if settings.USE_TZ else None
+ return date(datetime.now(tz=tzinfo), self.format_string)
class SpacelessNode(Node):
def __init__(self, nodelist):
Modified: django/trunk/tests/modeltests/timezones/tests.py
===================================================================
--- django/trunk/tests/modeltests/timezones/tests.py 2011-12-03 21:17:41 UTC
(rev 17168)
+++ django/trunk/tests/modeltests/timezones/tests.py 2011-12-04 22:11:12 UTC
(rev 17169)
@@ -790,6 +790,13 @@
self.assertTrue(tpl.render(ctx).startswith("2011"))
timezone._localtime = None
+ def test_now_template_tag_uses_current_time_zone(self):
+ # Regression for #17343
+ tpl = Template("{% now \"O\" %}")
+ self.assertEqual(tpl.render(Context({})), "+0300")
+ with timezone.override(ICT):
+ self.assertEqual(tpl.render(Context({})), "+0700")
+
TemplateTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False,
USE_TZ=True)(TemplateTests)
#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.