Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Apply the patch (patch.15426.diff) of the ticket #15053

  • Loading branch information...
commit ddb9fc152422743c18c1336413ad3255b5305385 1 parent 35ddeee
Pablo Martín authored July 16, 2012
3  django/template/base.py
@@ -227,9 +227,11 @@ def create_token(self, token_string, in_tag):
227 227
         else:
228 228
             token = Token(TOKEN_TEXT, token_string)
229 229
         token.lineno = self.lineno
  230
+        token.source = self.origin, (-1, -1) 
230 231
         self.lineno += token_string.count('\n')
231 232
         return token
232 233
 
  234
+
233 235
 class Parser(object):
234 236
     def __init__(self, tokens):
235 237
         self.tokens = tokens
@@ -304,6 +306,7 @@ def extend_nodelist(self, nodelist, node, token):
304 306
                                           "in the template." % node)
305 307
         if isinstance(nodelist, NodeList) and not isinstance(node, TextNode):
306 308
             nodelist.contains_nontext = True
  309
+        node.source = token.source
307 310
         nodelist.append(node)
308 311
 
309 312
     def enter_command(self, command, token):
4  django/template/debug.py
@@ -55,10 +55,6 @@ def create_nodelist(self):
55 55
     def create_variable_node(self, contents):
56 56
         return DebugVariableNode(contents)
57 57
 
58  
-    def extend_nodelist(self, nodelist, node, token):
59  
-        node.source = token.source
60  
-        super(DebugParser, self).extend_nodelist(nodelist, node, token)
61  
-
62 58
     def unclosed_block_tag(self, parse_until):
63 59
         command, source = self.command_stack.pop()
64 60
         msg = "Unclosed tag '%s'. Looking for one of: %s " % (command, ', '.join(parse_until))
31  django/template/loader.py
@@ -78,11 +78,17 @@ def __init__(self, display_name, loader, name, dirs):
78 78
     def reload(self):
79 79
         return self.loader(self.loadname, self.dirs)[0]
80 80
 
  81
+class LoaderOriginLite(object):
  82
+
  83
+    def __init__(self, display_name, loader, name, dirs):
  84
+        self.name = display_name
  85
+        self.loader, self.loadname, self.dirs = loader, name, dirs
  86
+
81 87
 def make_origin(display_name, loader, name, dirs):
82 88
     if settings.TEMPLATE_DEBUG and display_name:
83 89
         return LoaderOrigin(display_name, loader, name, dirs)
84 90
     else:
85  
-        return None
  91
+        return LoaderOriginLite(display_name, loader, name, dirs) 
86 92
 
87 93
 def find_template_loader(loader):
88 94
     if isinstance(loader, (tuple, list)):
@@ -117,7 +123,7 @@ def find_template_loader(loader):
117 123
     else:
118 124
         raise ImproperlyConfigured('Loader does not define a "load_template" callable template source loader')
119 125
 
120  
-def find_template(name, dirs=None):
  126
+def find_template(name, dirs=None, skip_template=None):
121 127
     # Calculate template_source_loaders the first time the function is executed
122 128
     # because putting this logic in the module-level namespace may cause
123 129
     # circular import errors. See Django ticket #1292.
@@ -129,20 +135,32 @@ def find_template(name, dirs=None):
129 135
             if loader is not None:
130 136
                 loaders.append(loader)
131 137
         template_source_loaders = tuple(loaders)
  138
+    template_candidate = None
132 139
     for loader in template_source_loaders:
133 140
         try:
134 141
             source, display_name = loader(name, dirs)
135  
-            return (source, make_origin(display_name, loader, name, dirs))
  142
+            if skip_template:
  143
+                extends_tags = source.nodelist[0]
  144
+                extends_tags_origin, extends_tags_source = extends_tags.source
  145
+                if extends_tags_origin.name == skip_template:
  146
+                    template_candidate = None
  147
+                    continue
  148
+                if not template_candidate:
  149
+                    template_candidate = (source, make_origin(display_name, loader, name, dirs))
  150
+            else:
  151
+                return (source, make_origin(display_name, loader, name, dirs))
136 152
         except TemplateDoesNotExist:
137 153
             pass
138  
-    raise TemplateDoesNotExist(name)
  154
+    if not template_candidate:
  155
+        raise TemplateDoesNotExist(name)
  156
+    return template_candidate
139 157
 
140  
-def get_template(template_name):
  158
+def get_template(template_name, skip_template=None):
141 159
     """
142 160
     Returns a compiled Template object for the given template name,
143 161
     handling template inheritance recursively.
144 162
     """
145  
-    template, origin = find_template(template_name)
  163
+    template, origin = find_template(template_name, skip_template=skip_template)
146 164
     if not hasattr(template, 'render'):
147 165
         # template needs to be compiled
148 166
         template = get_template_from_string(template, origin, template_name)
@@ -184,6 +202,7 @@ def select_template(template_name_list):
184 202
     not_found = []
185 203
     for template_name in template_name_list:
186 204
         try:
  205
+            import ipdb; ipdb.set_trace()
187 206
             return get_template(template_name)
188 207
         except TemplateDoesNotExist as e:
189 208
             if e.args[0] not in not_found:
14  django/template/loader_tags.py
... ...
@@ -1,7 +1,7 @@
1 1
 from django.conf import settings
2 2
 from django.template.base import TemplateSyntaxError, Library, Node, TextNode,\
3 3
     token_kwargs, Variable
4  
-from django.template.loader import get_template
  4
+from django.template.loader import find_template, get_template
5 5
 from django.utils.safestring import mark_safe
6 6
 
7 7
 register = Library()
@@ -94,10 +94,18 @@ def get_parent(self, context):
94 94
                     self.parent_name.token
95 95
             raise TemplateSyntaxError(error_msg)
96 96
         if hasattr(parent, 'render'):
97  
-            return parent # parent is a Template object
98  
-        return get_template(parent)
  97
+            return parent  # parent is a Template object
  98
+        origin, source = self.source
  99
+        return get_template(parent, skip_template=origin.name)
99 100
 
100 101
     def render(self, context):
  102
+        origin, source = self.source
  103
+        if origin and origin.loadname == self.parent_name:
  104
+            template = find_template(self.parent_name, skip_template=origin.name)
  105
+            template_source = template[0]
  106
+            extends_tags = template_source.nodelist[0]
  107
+            parent_origin, parent_source = extends_tags.source
  108
+            self.parent_name = getattr(parent_origin, 'name', None)
101 109
         compiled_parent = self.get_parent(context)
102 110
 
103 111
         if BLOCK_CONTEXT_KEY not in context.render_context:

0 notes on commit ddb9fc1

Please sign in to comment.
Something went wrong with that request. Please try again.