Django

Code

Changeset 7082

Show
Ignore:
Timestamp:
02/03/08 20:31:53 (10 months ago)
Author:
mtredinnick
Message:

Allow whitespace prior to an "extends" tag. This allows a little more formatting flexibility. Refs #6274.

Files:

Legend:

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

    r6673 r7082  
    11from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable 
    2 from django.template import Library, Node 
     2from django.template import Library, Node, TextNode 
    33from django.template.loader import get_template, get_template_from_string, find_template_source 
    44from django.conf import settings 
     
    6363    def render(self, context): 
    6464        compiled_parent = self.get_parent(context) 
    65         parent_is_child = isinstance(compiled_parent.nodelist[0], ExtendsNode) 
     65        if len(compiled_parent.nodelist) > 1: 
     66            n0, n1 = compiled_parent.nodelist[:2] 
     67        else: 
     68            n0, n1 = compiled_parent.nodelist[0], None 
     69        parent_is_child = (isinstance(n0, ExtendsNode) or 
     70                (isinstance(n0, TextNode) and isinstance(n1, ExtendsNode))) 
     71        if parent_is_child: 
     72            extend_node = int(not isinstance(n0, ExtendsNode)) 
    6673        parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) 
    6774        for block_node in self.nodelist.get_nodes_by_type(BlockNode): 
     
    7582                # it'll be checked when the parent node's render() is called. 
    7683                if parent_is_child: 
    77                     compiled_parent.nodelist[0].nodelist.append(block_node) 
     84                    compiled_parent.nodelist[extend_node].nodelist.append(block_node) 
    7885            else: 
    7986                # Keep any existing parents and add a new one. Used by BlockNode.