commit bb8200391b10cae732e54945ff3b5807ae55a595
Author: Stephen Kelly <steveire@gmail.com>
Date: Sat Jan 15 23:21:03 2011 +0100
Make the now tag accept single quoted strings.
Also move the test for a invalid string argument to a more suitable
place.
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 0662b5f..693a9d7 100644
a
|
b
|
def now(parser, token):
|
1071 | 1071 | |
1072 | 1072 | It is {% now "jS F Y H:i" %} |
1073 | 1073 | """ |
1074 | | bits = token.contents.split('"') |
1075 | | if len(bits) != 3: |
| 1074 | bits = token.split_contents() |
| 1075 | if len(bits) != 2: |
1076 | 1076 | raise TemplateSyntaxError("'now' statement takes one argument") |
1077 | | format_string = bits[1] |
| 1077 | format_string = bits[1][1:-1] |
1078 | 1078 | return NowNode(format_string) |
1079 | 1079 | now = register.tag(now) |
1080 | 1080 | |
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 99776e6..74bead1 100644
a
|
b
|
class Templates(unittest.TestCase):
|
934 | 934 | 'ifequal-split08': (r"{% ifequal a 'I\'m happy' %}yes{% else %}no{% endifequal %}", {'a': "I'm happy"}, "yes"), |
935 | 935 | 'ifequal-split09': (r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}", {'a': r"slash\man"}, "yes"), |
936 | 936 | 'ifequal-split10': (r"{% ifequal a 'slash\man' %}yes{% else %}no{% endifequal %}", {'a': r"slashman"}, "no"), |
| 937 | # Even though smart_split accepts 'j 'n' Y' as one item, FilterExpression does not. |
| 938 | 'ifequal-split11': (r"{% ifequal a 'j 'n' Y' %}yes{% else %}no{% endifequal %}", {'a': r"j 'n' Y"}, template.TemplateSyntaxError), |
937 | 939 | |
938 | 940 | # NUMERIC RESOLUTION |
939 | 941 | 'ifequal-numeric01': ('{% ifequal x 5 %}yes{% endifequal %}', {'x': '5'}, ''), |
… |
… |
class Templates(unittest.TestCase):
|
1349 | 1351 | 'now01': ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)), |
1350 | 1352 | |
1351 | 1353 | # Check parsing of escaped and special characters |
1352 | | 'now02': ('{% now "j "n" Y"%}', {}, template.TemplateSyntaxError), |
1353 | | # 'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + '"' + str(datetime.now().month) + '"' + str(datetime.now().year)), |
1354 | | # 'now04': ('{% now "j \nn\n Y"%}', {}, str(datetime.now().day) + '\n' + str(datetime.now().month) + '\n' + str(datetime.now().year)) |
| 1354 | 'now02': ('{% now "j " n " Y"%}', {}, template.TemplateSyntaxError), |
| 1355 | 'now03': ('{% now "j \"n\" Y"%}', {}, str(datetime.now().day) + ' "' + str(datetime.now().month) + '" ' + str(datetime.now().year)), |
| 1356 | 'now04': ('{% now "j \nn\n Y"%}', {}, '{% now "j \nn\n Y"%}'), |
| 1357 | |
| 1358 | 'now05': ("{% now 'j n Y' %}", {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)), |
1355 | 1359 | |
1356 | 1360 | ### URL TAG ######################################################## |
1357 | 1361 | # Successes |