Fixed #33036 -- Made simple_tag()/inclusion_tag() with takes_context raise TemplateSyntaxError when function has no parameters.
This commit is contained in:
parent
231de683d8
commit
5092f7247d
|
@ -243,7 +243,7 @@ def parse_bits(parser, bits, params, varargs, varkw, defaults,
|
||||||
keyword arguments.
|
keyword arguments.
|
||||||
"""
|
"""
|
||||||
if takes_context:
|
if takes_context:
|
||||||
if params[0] == 'context':
|
if params and params[0] == 'context':
|
||||||
params = params[1:]
|
params = params[1:]
|
||||||
else:
|
else:
|
||||||
raise TemplateSyntaxError(
|
raise TemplateSyntaxError(
|
||||||
|
|
|
@ -150,6 +150,17 @@ def simple_tag_without_context_parameter(arg):
|
||||||
simple_tag_without_context_parameter.anything = "Expected simple_tag_without_context_parameter __dict__"
|
simple_tag_without_context_parameter.anything = "Expected simple_tag_without_context_parameter __dict__"
|
||||||
|
|
||||||
|
|
||||||
|
@register.simple_tag(takes_context=True)
|
||||||
|
def simple_tag_takes_context_without_params():
|
||||||
|
"""Expected simple_tag_takes_context_without_params __doc__"""
|
||||||
|
return 'Expected result'
|
||||||
|
|
||||||
|
|
||||||
|
simple_tag_takes_context_without_params.anything = (
|
||||||
|
'Expected simple_tag_takes_context_without_params __dict__'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def escape_naive(context):
|
def escape_naive(context):
|
||||||
"""A tag that doesn't even think about escaping issues"""
|
"""A tag that doesn't even think about escaping issues"""
|
||||||
|
|
|
@ -242,6 +242,17 @@ def inclusion_tag_without_context_parameter(arg):
|
||||||
inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__"
|
inclusion_tag_without_context_parameter.anything = "Expected inclusion_tag_without_context_parameter __dict__"
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag('inclusion.html', takes_context=True)
|
||||||
|
def inclusion_tag_takes_context_without_params():
|
||||||
|
"""Expected inclusion_tag_takes_context_without_params __doc__"""
|
||||||
|
return {}
|
||||||
|
|
||||||
|
|
||||||
|
inclusion_tag_takes_context_without_params.anything = (
|
||||||
|
'Expected inclusion_tag_takes_context_without_params __dict__'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('inclusion_extends1.html')
|
@register.inclusion_tag('inclusion_extends1.html')
|
||||||
def inclusion_extends1():
|
def inclusion_extends1():
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -169,6 +169,16 @@ class SimpleTagTests(TagTestCase):
|
||||||
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
||||||
self.engine.from_string('{% load custom %}{% simple_tag_without_context_parameter 123 %}')
|
self.engine.from_string('{% load custom %}{% simple_tag_without_context_parameter 123 %}')
|
||||||
|
|
||||||
|
def test_simple_tag_missing_context_no_params(self):
|
||||||
|
msg = (
|
||||||
|
"'simple_tag_takes_context_without_params' is decorated with "
|
||||||
|
"takes_context=True so it must have a first argument of 'context'"
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
||||||
|
self.engine.from_string(
|
||||||
|
'{% load custom %}{% simple_tag_takes_context_without_params %}'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class InclusionTagTests(TagTestCase):
|
class InclusionTagTests(TagTestCase):
|
||||||
|
|
||||||
|
@ -256,6 +266,16 @@ class InclusionTagTests(TagTestCase):
|
||||||
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
||||||
self.engine.from_string('{% load inclusion %}{% inclusion_tag_without_context_parameter 123 %}')
|
self.engine.from_string('{% load inclusion %}{% inclusion_tag_without_context_parameter 123 %}')
|
||||||
|
|
||||||
|
def test_include_tag_missing_context_no_params(self):
|
||||||
|
msg = (
|
||||||
|
"'inclusion_tag_takes_context_without_params' is decorated with "
|
||||||
|
"takes_context=True so it must have a first argument of 'context'"
|
||||||
|
)
|
||||||
|
with self.assertRaisesMessage(TemplateSyntaxError, msg):
|
||||||
|
self.engine.from_string(
|
||||||
|
'{% load inclusion %}{% inclusion_tag_takes_context_without_params %}'
|
||||||
|
)
|
||||||
|
|
||||||
def test_inclusion_tags_from_template(self):
|
def test_inclusion_tags_from_template(self):
|
||||||
c = Context({'value': 42})
|
c = Context({'value': 42})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue