Fixed #5124 -- Added a reasonable error when "extends" is not the first template tag. Patch from k0001.
Refs #6274. git-svn-id: http://code.djangoproject.com/svn/django/trunk@7084 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
12ed18935b
commit
b9e088ae14
|
@ -289,6 +289,9 @@ class Parser(object):
|
|||
return NodeList()
|
||||
|
||||
def extend_nodelist(self, nodelist, node, token):
|
||||
if (node.must_be_first and nodelist and
|
||||
(not isinstance(nodelist[0], TextNode) or len(nodelist) > 2)):
|
||||
raise TemplateSyntaxError("%r must be the first tag in the template." % node)
|
||||
nodelist.append(node)
|
||||
|
||||
def enter_command(self, command, token):
|
||||
|
@ -708,6 +711,10 @@ class Variable(object):
|
|||
return current
|
||||
|
||||
class Node(object):
|
||||
# Set this to True for nodes that must be first in the template (although
|
||||
# they can be preceded by text nodes.
|
||||
must_be_first = False
|
||||
|
||||
def render(self, context):
|
||||
"Return the node rendered as a string"
|
||||
pass
|
||||
|
|
|
@ -37,11 +37,18 @@ class BlockNode(Node):
|
|||
self.parent = BlockNode(self.name, nodelist)
|
||||
|
||||
class ExtendsNode(Node):
|
||||
must_be_first = True
|
||||
|
||||
def __init__(self, nodelist, parent_name, parent_name_expr, template_dirs=None):
|
||||
self.nodelist = nodelist
|
||||
self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
|
||||
self.template_dirs = template_dirs
|
||||
|
||||
def __repr__(self):
|
||||
if self.parent_name_expr:
|
||||
return "<ExtendsNode: extends %s>" % self.parent_name_expr.token
|
||||
return '<ExtendsNode: extends "%s">' % self.parent_name
|
||||
|
||||
def get_parent(self, context):
|
||||
if self.parent_name_expr:
|
||||
self.parent_name = self.parent_name_expr.resolve(context)
|
||||
|
|
Loading…
Reference in New Issue