summaryrefslogtreecommitdiff
path: root/django/template
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-02-04 02:31:53 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2008-02-04 02:31:53 +0000
commit10015fae4de33dd5dfd38a3a14a9ddd4cb8442bf (patch)
tree2f2df73fd0bf8bda52382c3c78856cdb9c0a8dfd /django/template
parent66747182131de06b787d19c164f30fcfc0c625ce (diff)
Allow whitespace prior to an "extends" tag. This allows a little more formatting flexibility. Refs #6274.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7082 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template')
-rw-r--r--django/template/loader_tags.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index c83768ef91..ef4d8ab23a 100644
--- a/django/template/loader_tags.py
+++ b/django/template/loader_tags.py
@@ -1,5 +1,5 @@
from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable
-from django.template import Library, Node
+from django.template import Library, Node, TextNode
from django.template.loader import get_template, get_template_from_string, find_template_source
from django.conf import settings
from django.utils.safestring import mark_safe
@@ -62,7 +62,14 @@ class ExtendsNode(Node):
def render(self, context):
compiled_parent = self.get_parent(context)
- parent_is_child = isinstance(compiled_parent.nodelist[0], ExtendsNode)
+ if len(compiled_parent.nodelist) > 1:
+ n0, n1 = compiled_parent.nodelist[:2]
+ else:
+ n0, n1 = compiled_parent.nodelist[0], None
+ parent_is_child = (isinstance(n0, ExtendsNode) or
+ (isinstance(n0, TextNode) and isinstance(n1, ExtendsNode)))
+ if parent_is_child:
+ extend_node = int(not isinstance(n0, ExtendsNode))
parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)])
for block_node in self.nodelist.get_nodes_by_type(BlockNode):
# Check for a BlockNode with this node's name, and replace it if found.
@@ -74,7 +81,7 @@ class ExtendsNode(Node):
# add this BlockNode to the parent's ExtendsNode nodelist, so
# it'll be checked when the parent node's render() is called.
if parent_is_child:
- compiled_parent.nodelist[0].nodelist.append(block_node)
+ compiled_parent.nodelist[extend_node].nodelist.append(block_node)
else:
# Keep any existing parents and add a new one. Used by BlockNode.
parent_block.parent = block_node.parent