Ticket #6586: extend.3.patch

File extend.3.patch, 1.4 KB (added by fredd4, 17 years ago)

Caching on render works better (more correctly)

  • loader_tags.py

     
    4343        self.nodelist = nodelist
    4444        self.parent_name, self.parent_name_expr = parent_name, parent_name_expr
    4545        self.template_dirs = template_dirs
     46        self.compiled_parent = None
    4647
    4748    def __repr__(self):
    4849        if self.parent_name_expr:
     
    6768        else:
    6869            return get_template_from_string(source, origin, parent)
    6970
    70     def render(self, context):
     71    def process_parent( self, context ):
    7172        compiled_parent = self.get_parent(context)
    7273        pos = 0
    7374        while isinstance(compiled_parent.nodelist[pos], TextNode):
     
    9091                parent_block.parent = block_node.parent
    9192                parent_block.add_parent(parent_block.nodelist)
    9293                parent_block.nodelist = block_node.nodelist
     94        return compiled_parent
     95
     96    def render(self, context):
     97        if self.compiled_parent:
     98            compiled_parent = self.compiled_parent
     99        else:
     100            compiled_parent = self.process_parent(context)
     101            # cache it, if static
     102            if self.parent_name:
     103                self.compiled_parent = compiled_parent
     104
    93105        return compiled_parent.render(context)
    94106
    95107class ConstantIncludeNode(Node):
Back to Top