From 539a7ab993b000c6417018776d62de523eda7787 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Sat, 21 Apr 2007 04:13:52 +0000 Subject: [PATCH] Fixed #4098 -- fixed a syntax error when reporting errors in "with" template tag. Thanks cephelo@gmail.com. git-svn-id: http://code.djangoproject.com/svn/django/trunk@5048 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/defaulttags.py | 4 ++-- tests/regressiontests/templates/tests.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 448ad8a50b..ef57aa2449 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -990,7 +990,7 @@ def do_with(parser, token): """ Add a value to the context (inside of this block) for caching and easy access. - + For example:: {% with person.some_sql_method as total %} @@ -999,7 +999,7 @@ def do_with(parser, token): """ bits = list(token.split_contents()) if len(bits) != 4 or bits[2] != "as": - raise TemplateSyntaxError, "%r expected format is 'value as name'" % tagname + raise TemplateSyntaxError, "%r expected format is 'value as name'" % bits[0] var = parser.compile_filter(bits[1]) name = bits[3] nodelist = parser.parse(('endwith',)) diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index b544207be8..54fd9cf253 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -654,6 +654,9 @@ class Templates(unittest.TestCase): 'with01': ('{% with dict.key as key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, '50'), 'with02': ('{{ key }}{% with dict.key as key %}{{ key }}-{{ dict.key }}-{{ key }}{% endwith %}{{ key }}', {'dict': {'key':50}}, ('50-50-50', 'INVALID50-50-50INVALID')), + 'with-error01': ('{% with dict.key xx key %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError), + 'with-error02': ('{% with dict.key as %}{{ key }}{% endwith %}', {'dict': {'key':50}}, template.TemplateSyntaxError), + ### NOW TAG ######################################################## # Simple case 'now01' : ('{% now "j n Y"%}', {}, str(datetime.now().day) + ' ' + str(datetime.now().month) + ' ' + str(datetime.now().year)),