Changeset 7089
- Timestamp:
- 02/05/08 17:41:48 (10 months ago)
- Files:
-
- django/trunk/django/template/__init__.py (modified) (2 diffs)
- django/trunk/django/template/loader_tags.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/template/__init__.py
r7084 r7089 290 290 291 291 def extend_nodelist(self, nodelist, node, token): 292 if (node.must_be_first and nodelist and 293 (not isinstance(nodelist[0], TextNode) or len(nodelist) > 2)): 294 raise TemplateSyntaxError("%r must be the first tag in the template." % node) 292 if node.must_be_first and nodelist: 293 try: 294 if nodelist.contains_nontext: 295 raise AttributeError 296 except AttributeError: 297 raise TemplateSyntaxError("%r must be the first tag in the template." % node) 298 if isinstance(nodelist, NodeList) and not isinstance(node, TextNode): 299 nodelist.contains_nontext = True 295 300 nodelist.append(node) 296 301 … … 733 738 734 739 class NodeList(list): 740 # Set to True the first time a non-TextNode is inserted by 741 # extend_nodelist(). 742 contains_nontext = False 743 735 744 def render(self, context): 736 745 bits = [] django/trunk/django/template/loader_tags.py
r7085 r7089 70 70 def render(self, context): 71 71 compiled_parent = self.get_parent(context) 72 if len(compiled_parent.nodelist) > 1: 73 n0, n1 = compiled_parent.nodelist[:2] 74 else: 75 n0, n1 = compiled_parent.nodelist[0], None 76 parent_is_child = (isinstance(n0, ExtendsNode) or 77 (isinstance(n0, TextNode) and isinstance(n1, ExtendsNode))) 78 if parent_is_child: 79 extend_node = int(not isinstance(n0, ExtendsNode)) 72 pos = 0 73 while isinstance(compiled_parent.nodelist[pos], TextNode): 74 pos += 1 75 parent_is_child = isinstance(compiled_parent.nodelist[pos], ExtendsNode) 80 76 parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) 81 77 for block_node in self.nodelist.get_nodes_by_type(BlockNode): … … 89 85 # it'll be checked when the parent node's render() is called. 90 86 if parent_is_child: 91 compiled_parent.nodelist[ extend_node].nodelist.append(block_node)87 compiled_parent.nodelist[pos].nodelist.append(block_node) 92 88 else: 93 89 # Keep any existing parents and add a new one. Used by BlockNode.
