summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Phalip <jphalip@gmail.com>2012-01-24 08:02:34 +0000
committerJulien Phalip <jphalip@gmail.com>2012-01-24 08:02:34 +0000
commit6ae393d74db1f8e553c80951f3eaeb3ba16fc223 (patch)
treeb76f76575fb5953a10c88732a30c57193c79325d
parent804bd403838dbd01154f8f477b0ebf2045e7b4b5 (diff)
Fixed #15092 -- Made `{% now %}` work with single-quoted string arguments. Thanks to ninja_otoko for the report and to steveire, Aymeric Augustin and Claude Paroz for the patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17391 bcc190cf-cafb-0310-a4f2-bffc1f526a37
-rw-r--r--django/template/defaulttags.py6
-rw-r--r--tests/regressiontests/templates/tests.py18
2 files changed, 14 insertions, 10 deletions
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 701515a66d..fa54f457c8 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -1049,10 +1049,10 @@ def now(parser, token):
It is {% now "jS F Y H:i" %}
"""
- bits = token.contents.split('"')
- if len(bits) != 3:
+ bits = token.split_contents()
+ if len(bits) != 2:
raise TemplateSyntaxError("'now' statement takes one argument")
- format_string = bits[1]
+ format_string = bits[1][1:-1]
return NowNode(format_string)
@register.tag
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 1a1b360847..b067cb55b0 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -1462,14 +1462,18 @@ class Templates(unittest.TestCase):
### NOW TAG ########################################################
# Simple case
- 'now01': ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),
-
- # Check parsing of escaped and special characters
- 'now02': ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError),
- # 'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)),
- # 'now04': ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year))
+ 'now01': ('{% now "j n Y" %}', {}, "%d %d %d" % (
+ datetime.now().day, datetime.now().month, datetime.now().year)),
# Check parsing of locale strings
- 'now05': ('{% now "DATE_FORMAT" %}', {}, date_format(datetime.now())),
+ 'now02': ('{% now "DATE_FORMAT" %}', {}, date_format(datetime.now())),
+ # Also accept simple quotes - #15092
+ 'now03': ("{% now 'j n Y' %}", {}, "%d %d %d" % (
+ datetime.now().day, datetime.now().month, datetime.now().year)),
+ 'now04': ("{% now 'DATE_FORMAT' %}", {}, date_format(datetime.now())),
+ 'now05': ('''{% now 'j "n" Y'%}''', {}, '''%d "%d" %d''' % (
+ datetime.now().day, datetime.now().month, datetime.now().year)),
+ 'now06': ('''{% now "j 'n' Y"%}''', {}, '''%d '%d' %d''' % (
+ datetime.now().day, datetime.now().month, datetime.now().year)),
### URL TAG ########################################################
# Successes