diff options
| author | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-02-17 22:49:59 +0100 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@m4x.org> | 2015-02-19 22:10:56 +0100 |
| commit | cc4effba0bf07fbcb4dcc0074af969e698b6cc75 (patch) | |
| tree | efa5c227513168711732b0d14db6b09f62a21e4e /django/template/base.py | |
| parent | 84e7fec88ddfc4178500a80d640728226d77317a (diff) | |
[1.8.x] Set context.template instead of context.engine while rendering.
This opens more possibilities, like accessing context.template.origin.
It also follows the chain of objects instead of following a shortcut.
Backport of 1bfcc95 from master
Diffstat (limited to 'django/template/base.py')
| -rw-r--r-- | django/template/base.py | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/django/template/base.py b/django/template/base.py index b9fd47625b..76f77fc793 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -202,19 +202,19 @@ class Template(object): def render(self, context): "Display stage -- can be called many times" - # Set engine attribute here to avoid changing the signature of either - # Context.__init__ or Node.render. The engine is set only on the first - # call to render. Further calls e.g. for includes don't override it. - toplevel_render = context.engine is None + # Set context.template to the original template -- as opposed to + # extended or included templates -- during rendering. This may be + # used for accessing context.template.engine. + toplevel_render = context.template is None if toplevel_render: - context.engine = self.engine + context.template = self context.render_context.push() try: return self._render(context) finally: context.render_context.pop() if toplevel_render: - context.engine = None + context.template = None class Token(object): @@ -653,7 +653,7 @@ class FilterExpression(object): if ignore_failures: obj = None else: - string_if_invalid = context.engine.string_if_invalid + string_if_invalid = context.template.engine.string_if_invalid if string_if_invalid: if '%s' in string_if_invalid: return string_if_invalid % self.var @@ -845,7 +845,7 @@ class Variable(object): if getattr(current, 'do_not_call_in_templates', False): pass elif getattr(current, 'alters_data', False): - current = context.engine.string_if_invalid + current = context.template.engine.string_if_invalid else: try: # method call (assuming no args required) current = current() @@ -853,12 +853,12 @@ class Variable(object): try: getcallargs(current) except TypeError: # arguments *were* required - current = context.engine.string_if_invalid # invalid method call + current = context.template.engine.string_if_invalid # invalid method call else: raise except Exception as e: if getattr(e, 'silent_variable_failure', False): - current = context.engine.string_if_invalid + current = context.template.engine.string_if_invalid else: raise @@ -1275,9 +1275,9 @@ class Library(object): elif isinstance(getattr(file_name, 'template', None), Template): t = file_name.template elif not isinstance(file_name, six.string_types) and is_iterable(file_name): - t = context.engine.select_template(file_name) + t = context.template.engine.select_template(file_name) else: - t = context.engine.get_template(file_name) + t = context.template.engine.get_template(file_name) self.nodelist = t.nodelist new_context = context.new(_dict) # Copy across the CSRF token, if present, because |
