From 218cc71073012cc4e72c150421fc89da626d2923 Mon Sep 17 00:00:00 2001 From: Preston Timmons Date: Thu, 14 Jan 2016 20:36:05 -0600 Subject: [1.9.x] Fixed #25848 -- Set template origin on each node. Prior to 55f12f8709, the template origin was available on each node via `self.token.source[0]`. This behavior was removed when debug handling was simplified, but 3rd-party debugging tools still depend on its presence. This updates the Parser to set origin on individual nodes. This enables the source template to be determined even when template extending or including is used. Backport of cfda1fa3f8d95f0f4a369da9021dbd770e5fa44a from master --- django/template/base.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'django/template/base.py') diff --git a/django/template/base.py b/django/template/base.py index 0df744f43e..30d339a748 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -224,6 +224,7 @@ class Template(object): tokens = lexer.tokenize() parser = Parser( tokens, self.engine.template_libraries, self.engine.template_builtins, + self.origin, ) try: @@ -444,7 +445,7 @@ class DebugLexer(Lexer): class Parser(object): - def __init__(self, tokens, libraries=None, builtins=None): + def __init__(self, tokens, libraries=None, builtins=None, origin=None): self.tokens = tokens self.tags = {} self.filters = {} @@ -458,6 +459,7 @@ class Parser(object): self.libraries = libraries for builtin in builtins: self.add_library(builtin) + self.origin = origin def parse(self, parse_until=None): """ @@ -534,8 +536,10 @@ class Parser(object): ) if isinstance(nodelist, NodeList) and not isinstance(node, TextNode): nodelist.contains_nontext = True - # Set token here since we can't modify the node __init__ method + # Set origin and token here since we can't modify the node __init__() + # method. node.token = token + node.origin = self.origin nodelist.append(node) def error(self, token, e): -- cgit v1.3