Ticket #9154: templates_optimizations_r9109.diff
File templates_optimizations_r9109.diff, 4.5 KB (added by , 16 years ago) |
---|
-
django/contrib/admin/templatetags/log.py
15 15 context[self.varname] = LogEntry.objects.all().select_related('content_type', 'user')[:self.limit] 16 16 else: 17 17 if not self.user.isdigit(): 18 self.user = context[self.user].id 19 context[self.varname] = LogEntry.objects.filter(user__id__exact=self.user).select_related('content_type', 'user')[:self.limit] 18 user_id = context[self.user].id 19 else: 20 user_id = self.user 21 context[self.varname] = LogEntry.objects.filter(user__id__exact=user_id).select_related('content_type', 'user')[:self.limit] 20 22 return '' 21 23 22 24 class DoGetAdminLog: -
django/template/loader_tags.py
1 import copy 2 1 3 from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable 2 4 from django.template import Library, Node, TextNode 3 from django.template.loader import get_template , get_template_from_string, find_template_source5 from django.template.loader import get_template 4 6 from django.conf import settings 5 7 from django.utils.safestring import mark_safe 6 8 … … 43 45 self.nodelist = nodelist 44 46 self.parent_name, self.parent_name_expr = parent_name, parent_name_expr 45 47 self.template_dirs = template_dirs 48 if self.parent_name_expr is None: 49 self.compiled_parent = copy.deepcopy(self.get_parent(context=None)) 50 else: 51 self.compiled_parent = None 46 52 47 53 def __repr__(self): 48 54 if self.parent_name_expr: … … 61 67 if hasattr(parent, 'render'): 62 68 return parent # parent is a Template object 63 69 try: 64 source, origin = find_template_source(parent, self.template_dirs)70 return get_template(parent, self.template_dirs) 65 71 except TemplateDoesNotExist: 66 72 raise TemplateSyntaxError, "Template %r cannot be extended, because it doesn't exist" % parent 67 else:68 return get_template_from_string(source, origin, parent)69 73 70 74 def render(self, context): 71 compiled_parent = self.get_parent(context) 75 if self.compiled_parent is not None: 76 compiled_parent = self.compiled_parent 77 else: 78 compiled_parent = self.get_parent(context) 72 79 parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) 73 80 for block_node in self.nodelist.get_nodes_by_type(BlockNode): 74 81 # Check for a BlockNode with this node's name, and replace it if found. … … 156 163 uses the literal value "base" as the name of the parent template to extend, 157 164 or ``{% extends variable %}`` uses the value of ``variable`` as either the 158 165 name of the parent template to extend (if it evaluates to a string) or as 159 the parent temp ate itelf (if it evaluates to a Template object).166 the parent template itself (if it evaluates to a Template object). 160 167 """ 161 168 bits = token.contents.split() 162 169 if len(bits) != 2: -
django/template/loader.py
26 26 27 27 template_source_loaders = None 28 28 29 _template_cache = {} 30 29 31 class LoaderOrigin(Origin): 30 32 def __init__(self, display_name, loader, name, dirs): 31 33 super(LoaderOrigin, self).__init__(display_name) … … 72 74 pass 73 75 raise TemplateDoesNotExist, name 74 76 75 def get_template(template_name ):77 def get_template(template_name, dirs=None): 76 78 """ 77 79 Returns a compiled Template object for the given template name, 78 80 handling template inheritance recursively. 79 81 """ 80 source, origin = find_template_source(template_name) 82 if not settings.TEMPLATE_DEBUG and template_name in _template_cache: 83 return _template_cache[template_name] 84 source, origin = find_template_source(template_name, dirs) 81 85 template = get_template_from_string(source, origin, template_name) 86 _template_cache[template_name] = template 82 87 return template 83 88 84 89 def get_template_from_string(source, origin=None, name=None):