summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-11-22 21:33:40 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-11-23 11:54:17 +0100
commit6294bd3903e12507c4e70e012dade82d0f52c388 (patch)
tree5756d5318c51ccd589d3a3c69a928843a72541e2 /django
parent47a131b9446eb9b31e57554f17310bc2fd43a26f (diff)
Encapsulated TEMPLATE_DEBUG in Engine.
Diffstat (limited to 'django')
-rw-r--r--django/template/base.py5
-rw-r--r--django/template/defaulttags.py2
-rw-r--r--django/template/engine.py8
-rw-r--r--django/template/loader_tags.py3
-rw-r--r--django/test/signals.py1
5 files changed, 10 insertions, 9 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 85bafdd3b4..22e411270d 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -7,7 +7,6 @@ from inspect import getargspec, getcallargs
import warnings
from django.apps import apps
-from django.conf import settings
from django.template.context import (BaseContext, Context, RequestContext, # NOQA: imported for backwards compatibility
ContextPopException)
from django.utils import lru_cache
@@ -126,11 +125,11 @@ class Template(object):
except UnicodeDecodeError:
raise TemplateEncodingError("Templates can only be constructed "
"from unicode or UTF-8 strings.")
- if settings.TEMPLATE_DEBUG and origin is None:
- origin = StringOrigin(template_string)
if engine is None:
from .engine import Engine
engine = Engine.get_default()
+ if engine.debug and origin is None:
+ origin = StringOrigin(template_string)
self.nodelist = engine.compile_string(template_string, origin)
self.name = name
self.origin = origin
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index fa1cbfa98e..8a2fb944f2 100644
--- a/django/template/defaulttags.py
+++ b/django/template/defaulttags.py
@@ -210,7 +210,7 @@ class ForNode(Node):
context[self.loopvars[0]] = item
# In TEMPLATE_DEBUG mode provide source of the node which
# actually raised the exception
- if settings.TEMPLATE_DEBUG:
+ if context.engine.debug:
for node in self.nodelist_loop:
try:
nodelist.append(node.render(context))
diff --git a/django/template/engine.py b/django/template/engine.py
index ce497ad234..36991133f6 100644
--- a/django/template/engine.py
+++ b/django/template/engine.py
@@ -19,7 +19,7 @@ class Engine(object):
def __init__(self, dirs=None, app_dirs=False,
allowed_include_roots=None, context_processors=None,
- loaders=None, string_if_invalid='',
+ debug=False, loaders=None, string_if_invalid='',
file_charset=None):
if dirs is None:
dirs = []
@@ -42,6 +42,7 @@ class Engine(object):
self.app_dirs = app_dirs
self.allowed_include_roots = allowed_include_roots
self.context_processors = context_processors
+ self.debug = debug
self.loaders = loaders
self.string_if_invalid = string_if_invalid
self.file_charset = file_charset
@@ -54,6 +55,7 @@ class Engine(object):
dirs=settings.TEMPLATE_DIRS,
allowed_include_roots=settings.ALLOWED_INCLUDE_ROOTS,
context_processors=settings.TEMPLATE_CONTEXT_PROCESSORS,
+ debug=settings.TEMPLATE_DEBUG,
loaders=settings.TEMPLATE_LOADERS,
string_if_invalid=settings.TEMPLATE_STRING_IF_INVALID,
file_charset=settings.FILE_CHARSET,
@@ -211,7 +213,7 @@ class Engine(object):
"""
Compiles template_string into a NodeList ready for rendering.
"""
- if settings.TEMPLATE_DEBUG:
+ if self.debug:
from .debug import DebugLexer, DebugParser
lexer_class, parser_class = DebugLexer, DebugParser
else:
@@ -222,7 +224,7 @@ class Engine(object):
return parser.parse()
def make_origin(self, display_name, loader, name, dirs):
- if settings.TEMPLATE_DEBUG and display_name:
+ if self.debug and display_name:
# Inner import to avoid circular dependency
from .loader import LoaderOrigin
return LoaderOrigin(display_name, loader, name, dirs)
diff --git a/django/template/loader_tags.py b/django/template/loader_tags.py
index e70478d06b..e758990c72 100644
--- a/django/template/loader_tags.py
+++ b/django/template/loader_tags.py
@@ -1,6 +1,5 @@
from collections import defaultdict
-from django.conf import settings
from django.template.base import TemplateSyntaxError, Library, Node, TextNode,\
token_kwargs, Variable
from django.template.loader import get_template
@@ -154,7 +153,7 @@ class IncludeNode(Node):
with context.push(**values):
return template.render(context)
except Exception:
- if settings.TEMPLATE_DEBUG:
+ if context.engine.debug:
raise
return ''
diff --git a/django/test/signals.py b/django/test/signals.py
index 558f6cef21..066abdfc80 100644
--- a/django/test/signals.py
+++ b/django/test/signals.py
@@ -83,6 +83,7 @@ def reset_default_template_engine(**kwargs):
'TEMPLATE_DIRS',
'ALLOWED_INCLUDE_ROOTS',
'TEMPLATE_CONTEXT_PROCESSORS',
+ 'TEMPLATE_DEBUG',
'TEMPLATE_LOADERS',
'TEMPLATE_STRING_IF_INVALID',
'FILE_CHARSET',