0
0
mirror of https://github.com/django/django.git synced 2024-12-01 15:42:04 +01:00

Added to each Context a reference to the Engine.

It's only available during the rendering.
This commit is contained in:
Aymeric Augustin 2014-11-20 22:12:21 +01:00
parent a2dd08666c
commit 5b1bb40216
2 changed files with 13 additions and 3 deletions

View File

@ -150,11 +150,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
if toplevel_render:
context.engine = self.engine
context.render_context.push()
try:
return self._render(context)
finally:
context.render_context.pop()
if toplevel_render:
context.engine = None
def compile_string(template_string, origin):
@ -1236,6 +1244,7 @@ class Library(object):
'current_app': context.current_app,
'use_l10n': context.use_l10n,
'use_tz': context.use_tz,
'engine': context.engine,
})
# Copy across the CSRF token, if present, because
# inclusion tags are often used for forms, and we need

View File

@ -121,11 +121,12 @@ class BaseContext(object):
class Context(BaseContext):
"A stack container for variable context"
def __init__(self, dict_=None, autoescape=True, current_app=None,
use_l10n=None, use_tz=None):
use_l10n=None, use_tz=None, engine=None):
self.autoescape = autoescape
self.current_app = current_app
self.use_l10n = use_l10n
self.use_tz = use_tz
self.engine = engine
self.render_context = RenderContext()
super(Context, self).__init__(dict_)
@ -186,9 +187,9 @@ class RequestContext(Context):
using the "processors" keyword argument.
"""
def __init__(self, request, dict_=None, processors=None, current_app=None,
use_l10n=None, use_tz=None):
use_l10n=None, use_tz=None, engine=None):
Context.__init__(self, dict_, current_app=current_app,
use_l10n=use_l10n, use_tz=use_tz)
use_l10n=use_l10n, use_tz=use_tz, engine=engine)
if processors is None:
processors = ()
else: