Django

Code

Show
Ignore:
Timestamp:
02/05/08 17:41:48 (1 year ago)
Author:
mtredinnick
Message:

Tweaked [7082] and [7084] a little bit to also allow comment nodes prior to the extends tag.

This would be little less fiddly if we knew nodelist were always of type
NodeList?, but they could be normal lists. Or if we merged successive TextNodes?,
instead of appending them. Something to think about going forwards.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/loader_tags.py

    r7085 r7089  
    7070    def render(self, context): 
    7171        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) 
    8076        parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) 
    8177        for block_node in self.nodelist.get_nodes_by_type(BlockNode): 
     
    8985                # it'll be checked when the parent node's render() is called. 
    9086                if parent_is_child: 
    91                     compiled_parent.nodelist[extend_node].nodelist.append(block_node) 
     87                    compiled_parent.nodelist[pos].nodelist.append(block_node) 
    9288            else: 
    9389                # Keep any existing parents and add a new one. Used by BlockNode.