Kaydet (Commit) 33bb3cd4 authored tarafından Aymeric Augustin's avatar Aymeric Augustin

Fixed #17343 -- Changed the {% now %} tag to use the current time zone when time…

Fixed #17343 -- Changed the {% now %} tag to use the current time zone when time zone support is enabled. Thanks oinopion for the report.


git-svn-id: http://code.djangoproject.com/svn/django/trunk@17169 bcc190cf-cafb-0310-a4f2-bffc1f526a37
üst e42360b5
...@@ -15,6 +15,7 @@ from django.template.smartif import IfParser, Literal ...@@ -15,6 +15,7 @@ from django.template.smartif import IfParser, Literal
from django.template.defaultfilters import date from django.template.defaultfilters import date
from django.utils.encoding import smart_str, smart_unicode from django.utils.encoding import smart_str, smart_unicode
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils import timezone
register = Library() register = Library()
...@@ -343,7 +344,8 @@ class NowNode(Node): ...@@ -343,7 +344,8 @@ class NowNode(Node):
self.format_string = format_string self.format_string = format_string
def render(self, context): 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): class SpacelessNode(Node):
def __init__(self, nodelist): def __init__(self, nodelist):
......
...@@ -790,6 +790,13 @@ class TemplateTests(BaseDateTimeTests): ...@@ -790,6 +790,13 @@ class TemplateTests(BaseDateTimeTests):
self.assertTrue(tpl.render(ctx).startswith("2011")) self.assertTrue(tpl.render(ctx).startswith("2011"))
timezone._localtime = None 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) TemplateTests = override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=True)(TemplateTests)
#@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False) #@override_settings(DATETIME_FORMAT='c', USE_L10N=False, USE_TZ=False)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment