Ticket #9154: templates_optimizations_r9076.diff
File templates_optimizations_r9076.diff, 4.3 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].id19 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 context[self.varname] = LogEntry.objects.filter(user__id__exact=user_id).select_related('content_type', 'user')[:self.limit] 20 20 return '' 21 21 22 22 class DoGetAdminLog: -
django/template/loader_tags.py
1 1 from django.template import TemplateSyntaxError, TemplateDoesNotExist, Variable 2 2 from django.template import Library, Node, TextNode 3 from django.template.loader import get_template , get_template_from_string, find_template_source3 from django.template.loader import get_template 4 4 from django.conf import settings 5 5 from django.utils.safestring import mark_safe 6 6 … … 43 43 self.nodelist = nodelist 44 44 self.parent_name, self.parent_name_expr = parent_name, parent_name_expr 45 45 self.template_dirs = template_dirs 46 self.compiled_parent = self.get_parent() 46 47 47 48 def __repr__(self): 48 49 if self.parent_name_expr: 49 50 return "<ExtendsNode: extends %s>" % self.parent_name_expr.token 50 51 return '<ExtendsNode: extends "%s">' % self.parent_name 51 52 52 def get_parent(self, context): 53 if self.parent_name_expr: 54 self.parent_name = self.parent_name_expr.resolve(context) 53 def get_parent(self): 55 54 parent = self.parent_name 56 55 if not parent: 57 56 error_msg = "Invalid template name in 'extends' tag: %r." % parent … … 61 60 if hasattr(parent, 'render'): 62 61 return parent # parent is a Template object 63 62 try: 64 source, origin = find_template_source(parent, self.template_dirs)63 return get_template(parent, self.template_dirs) 65 64 except TemplateDoesNotExist: 66 65 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 66 70 67 def render(self, context): 71 compiled_parent = self. get_parent(context)68 compiled_parent = self.compiled_parent 72 69 parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) 73 70 for block_node in self.nodelist.get_nodes_by_type(BlockNode): 74 71 # Check for a BlockNode with this node's name, and replace it if found. -
django/template/loader.py
22 22 23 23 from django.core.exceptions import ImproperlyConfigured 24 24 from django.template import Origin, Template, Context, TemplateDoesNotExist, add_to_builtins 25 from django.utils.functional import memoize 25 26 from django.conf import settings 26 27 27 28 template_source_loaders = None 28 29 30 _template_cache = {} 31 29 32 class LoaderOrigin(Origin): 30 33 def __init__(self, display_name, loader, name, dirs): 31 34 super(LoaderOrigin, self).__init__(display_name) … … 72 75 pass 73 76 raise TemplateDoesNotExist, name 74 77 75 def get_template(template_name ):78 def get_template(template_name, dirs=None): 76 79 """ 77 80 Returns a compiled Template object for the given template name, 78 81 handling template inheritance recursively. 79 82 """ 80 source, origin = find_template_source(template_name) 83 if template_name in _template_cache: 84 return _template_cache[template_name] 85 source, origin = find_template_source(template_name, dirs) 81 86 template = get_template_from_string(source, origin, template_name) 87 _template_cache[template_name] = template 82 88 return template 83 89 84 90 def get_template_from_string(source, origin=None, name=None):