Ticket #15053: patch.15426.diff
File patch.15426.diff, 5.9 KB (added by , 14 years ago) |
---|
-
template/base.py
195 195 token = Token(TOKEN_COMMENT, content) 196 196 else: 197 197 token = Token(TOKEN_TEXT, token_string) 198 token.source = self.origin, (-1, -1) 198 199 token.lineno = self.lineno 199 200 self.lineno += token_string.count('\n') 200 201 return token … … 268 269 raise TemplateSyntaxError("%r must be the first tag in the template." % node) 269 270 if isinstance(nodelist, NodeList) and not isinstance(node, TextNode): 270 271 nodelist.contains_nontext = True 272 node.source = token.source 271 273 nodelist.append(node) 272 274 273 275 def enter_command(self, command, token): -
template/loader_tags.py
2 2 from django.template.base import Library, Node, TextNode 3 3 from django.template.context import Context 4 4 from django.template.defaulttags import token_kwargs 5 from django.template.loader import get_template5 from django.template.loader import find_template, get_template 6 6 from django.conf import settings 7 7 from django.utils.safestring import mark_safe 8 8 … … 99 99 raise TemplateSyntaxError(error_msg) 100 100 if hasattr(parent, 'render'): 101 101 return parent # parent is a Template object 102 return get_template(parent) 102 origin, source = self.source 103 return get_template(parent, skip_template=origin.name) 103 104 104 105 def render(self, context): 106 origin, source = self.source 107 if origin and origin.loadname == self.parent_name: 108 template = find_template(self.parent_name, skip_template=origin.name) 109 template_source = template[0] 110 extends_tags = template_source.nodelist[0] 111 parent_origin, parent_source = extends_tags.source 112 self.parent_name = getattr(parent_origin, 'name', None) 105 113 compiled_parent = self.get_parent(context) 106 114 107 115 if BLOCK_CONTEXT_KEY not in context.render_context: -
template/debug.py
54 54 def create_variable_node(self, contents): 55 55 return DebugVariableNode(contents) 56 56 57 def extend_nodelist(self, nodelist, node, token):58 node.source = token.source59 super(DebugParser, self).extend_nodelist(nodelist, node, token)60 61 57 def unclosed_block_tag(self, parse_until): 62 58 command, source = self.command_stack.pop() 63 59 msg = "Unclosed tag '%s'. Looking for one of: %s " % (command, ', '.join(parse_until)) -
template/loader.py
78 78 def reload(self): 79 79 return self.loader(self.loadname, self.dirs)[0] 80 80 81 82 class LoaderOriginLite(object): 83 84 def __init__(self, display_name, loader, name, dirs): 85 self.name = display_name 86 self.loader, self.loadname, self.dirs = loader, name, dirs 87 88 81 89 def make_origin(display_name, loader, name, dirs): 82 90 if settings.TEMPLATE_DEBUG and display_name: 83 91 return LoaderOrigin(display_name, loader, name, dirs) 84 92 else: 85 return None93 return LoaderOriginLite(display_name, loader, name, dirs) 86 94 87 95 def find_template_loader(loader): 88 96 if isinstance(loader, (tuple, list)): … … 117 125 else: 118 126 raise ImproperlyConfigured('Loader does not define a "load_template" callable template source loader') 119 127 120 def find_template(name, dirs=None): 128 129 def find_template(name, dirs=None, skip_template=None): 121 130 # Calculate template_source_loaders the first time the function is executed 122 131 # because putting this logic in the module-level namespace may cause 123 132 # circular import errors. See Django ticket #1292. … … 129 138 if loader is not None: 130 139 loaders.append(loader) 131 140 template_source_loaders = tuple(loaders) 141 template_candidate = None 132 142 for loader in template_source_loaders: 133 143 try: 134 144 source, display_name = loader(name, dirs) 135 return (source, make_origin(display_name, loader, name, dirs)) 145 if skip_template: 146 extends_tags = source.nodelist[0] 147 extends_tags_origin, extends_tags_source = extends_tags.source 148 if extends_tags_origin.name == skip_template: 149 template_candidate = None 150 continue 151 if not template_candidate: 152 template_candidate = (source, make_origin(display_name, loader, name, dirs)) 153 else: 154 return (source, make_origin(display_name, loader, name, dirs)) 136 155 except TemplateDoesNotExist: 137 156 pass 138 raise TemplateDoesNotExist(name) 157 if not template_candidate: 158 raise TemplateDoesNotExist(name) 159 return template_candidate 139 160 140 161 def find_template_source(name, dirs=None): 141 162 # For backward compatibility … … 149 170 raise Exception("Found a compiled template that is incompatible with the deprecated `django.template.loaders.find_template_source` function.") 150 171 return template, origin 151 172 152 def get_template(template_name ):173 def get_template(template_name, skip_template=None): 153 174 """ 154 175 Returns a compiled Template object for the given template name, 155 176 handling template inheritance recursively. 156 177 """ 157 template, origin = find_template(template_name )178 template, origin = find_template(template_name, skip_template=skip_template) 158 179 if not hasattr(template, 'render'): 159 180 # template needs to be compiled 160 181 template = get_template_from_string(template, origin, template_name)