Ticket #17660: 17660.patch
File 17660.patch, 2.3 KB (added by , 13 years ago) |
---|
-
django/template/loader_tags.py
74 74 class ExtendsNode(Node): 75 75 must_be_first = True 76 76 77 def __init__(self, nodelist, parent_name, parent_name_expr,template_dirs=None):77 def __init__(self, nodelist, parent_name, template_dirs=None): 78 78 self.nodelist = nodelist 79 self.parent_name , self.parent_name_expr = parent_name, parent_name_expr79 self.parent_name = parent_name 80 80 self.template_dirs = template_dirs 81 81 self.blocks = dict([(n.name, n) for n in nodelist.get_nodes_by_type(BlockNode)]) 82 82 83 83 def __repr__(self): 84 if self.parent_name_expr:85 return "<ExtendsNode: extends %s>" % self.parent_name_expr.token86 84 return '<ExtendsNode: extends "%s">' % self.parent_name 87 85 88 86 def get_parent(self, context): 89 if self.parent_name_expr: 90 parent = self.parent_name_expr.resolve(context) 91 else: 92 parent = self.parent_name 87 parent = self.parent_name.resolve(context) 93 88 if not parent: 94 89 error_msg = "Invalid template name in 'extends' tag: %r." % parent 95 if self.parent_name_expr:96 error_msg += " Got this from the '%s' variable." % self.parent_name_expr.token97 90 raise TemplateSyntaxError(error_msg) 98 91 if hasattr(parent, 'render'): 99 92 return parent # parent is a Template object … … 212 205 bits = token.split_contents() 213 206 if len(bits) != 2: 214 207 raise TemplateSyntaxError("'%s' takes one argument" % bits[0]) 215 parent_name, parent_name_expr = None, None 216 if bits[1][0] in ('"', "'") and bits[1][-1] == bits[1][0]: 217 parent_name = bits[1][1:-1] 218 else: 219 parent_name_expr = parser.compile_filter(bits[1]) 208 parent_name = parser.compile_filter(bits[1]) 220 209 nodelist = parser.parse() 221 210 if nodelist.get_nodes_by_type(ExtendsNode): 222 211 raise TemplateSyntaxError("'%s' cannot appear more than once in the same template" % bits[0]) 223 return ExtendsNode(nodelist, parent_name , parent_name_expr)212 return ExtendsNode(nodelist, parent_name) 224 213 225 214 @register.tag('include') 226 215 def do_include(parser, token):