Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit ddb9fc152422743c18c1336413ad3255b5305385 1 parent 35ddeee
Pablo Martín goinnn authored
3  django/template/base.py
View
@@ -227,9 +227,11 @@ def create_token(self, token_string, in_tag):
else:
token = Token(TOKEN_TEXT, token_string)
token.lineno = self.lineno
+ token.source = self.origin, (-1, -1)
self.lineno += token_string.count('\n')
return token
+
class Parser(object):
def __init__(self, tokens):
self.tokens = tokens
@@ -304,6 +306,7 @@ def extend_nodelist(self, nodelist, node, token):
"in the template." % node)
if isinstance(nodelist, NodeList) and not isinstance(node, TextNode):
nodelist.contains_nontext = True
+ node.source = token.source
nodelist.append(node)
def enter_command(self, command, token):
4 django/template/debug.py
View
@@ -55,10 +55,6 @@ def create_nodelist(self):
def create_variable_node(self, contents):
return DebugVariableNode(contents)
- def extend_nodelist(self, nodelist, node, token):
- node.source = token.source
- super(DebugParser, self).extend_nodelist(nodelist, node, token)
-
def unclosed_block_tag(self, parse_until):
command, source = self.command_stack.pop()
msg = "Unclosed tag '%s'. Looking for one of: %s " % (command, ', '.join(parse_until))
31 django/template/loader.py
View
@@ -78,11 +78,17 @@ def __init__(self, display_name, loader, name, dirs):
def reload(self):
return self.loader(self.loadname, self.dirs)[0]
+class LoaderOriginLite(object):
+
+ def __init__(self, display_name, loader, name, dirs):
+ self.name = display_name
+ self.loader, self.loadname, self.dirs = loader, name, dirs
+
def make_origin(display_name, loader, name, dirs):
if settings.TEMPLATE_DEBUG and display_name:
return LoaderOrigin(display_name, loader, name, dirs)
else:
- return None
+ return LoaderOriginLite(display_name, loader, name, dirs)
def find_template_loader(loader):
if isinstance(loader, (tuple, list)):
@@ -117,7 +123,7 @@ def find_template_loader(loader):
else:
raise ImproperlyConfigured('Loader does not define a "load_template" callable template source loader')
-def find_template(name, dirs=None):
+def find_template(name, dirs=None, skip_template=None):
# Calculate template_source_loaders the first time the function is executed
# because putting this logic in the module-level namespace may cause
# circular import errors. See Django ticket #1292.
@@ -129,20 +135,32 @@ def find_template(name, dirs=None):
if loader is not None:
loaders.append(loader)
template_source_loaders = tuple(loaders)
+ template_candidate = None
for loader in template_source_loaders:
try:
source, display_name = loader(name, dirs)
- return (source, make_origin(display_name, loader, name, dirs))
+ if skip_template:
+ extends_tags = source.nodelist[0]
+ extends_tags_origin, extends_tags_source = extends_tags.source
+ if extends_tags_origin.name == skip_template:
+ template_candidate = None
+ continue
+ if not template_candidate:
+ template_candidate = (source, make_origin(display_name, loader, name, dirs))
+ else:
+ return (source, make_origin(display_name, loader, name, dirs))
except TemplateDoesNotExist:
pass
- raise TemplateDoesNotExist(name)
+ if not template_candidate:
+ raise TemplateDoesNotExist(name)
+ return template_candidate
-def get_template(template_name):
+def get_template(template_name, skip_template=None):
"""
Returns a compiled Template object for the given template name,
handling template inheritance recursively.
"""
- template, origin = find_template(template_name)
+ template, origin = find_template(template_name, skip_template=skip_template)
if not hasattr(template, 'render'):
# template needs to be compiled
template = get_template_from_string(template, origin, template_name)
@@ -184,6 +202,7 @@ def select_template(template_name_list):
not_found = []
for template_name in template_name_list:
try:
+ import ipdb; ipdb.set_trace()
return get_template(template_name)
except TemplateDoesNotExist as e:
if e.args[0] not in not_found:
14 django/template/loader_tags.py
View
@@ -1,7 +1,7 @@
from django.conf import settings
from django.template.base import TemplateSyntaxError, Library, Node, TextNode,\
token_kwargs, Variable
-from django.template.loader import get_template
+from django.template.loader import find_template, get_template
from django.utils.safestring import mark_safe
register = Library()
@@ -94,10 +94,18 @@ def get_parent(self, context):
self.parent_name.token
raise TemplateSyntaxError(error_msg)
if hasattr(parent, 'render'):
- return parent # parent is a Template object
- return get_template(parent)
+ return parent # parent is a Template object
+ origin, source = self.source
+ return get_template(parent, skip_template=origin.name)
def render(self, context):
+ origin, source = self.source
+ if origin and origin.loadname == self.parent_name:
+ template = find_template(self.parent_name, skip_template=origin.name)
+ template_source = template[0]
+ extends_tags = template_source.nodelist[0]
+ parent_origin, parent_source = extends_tags.source
+ self.parent_name = getattr(parent_origin, 'name', None)
compiled_parent = self.get_parent(context)
if BLOCK_CONTEXT_KEY not in context.render_context:
Please sign in to comment.
Something went wrong with that request. Please try again.