summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2014-11-22 18:52:55 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2014-11-23 11:53:53 +0100
commit47a131b9446eb9b31e57554f17310bc2fd43a26f (patch)
tree6e13b9161d5289f8a56c46b5b7ffe9aa4e70deb3 /django
parent37505b6397058bcc3460f23d48a7de9641cd6ef0 (diff)
Encapsulated TEMPLATE_STRING_IF_INVALID in Engine.
Diffstat (limited to 'django')
-rw-r--r--django/template/base.py25
-rw-r--r--django/templatetags/i18n.py2
2 files changed, 11 insertions, 16 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 6044226254..85bafdd3b4 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -71,10 +71,6 @@ libraries = {}
# global list of libraries to load by default for a new parser
builtins = []
-# True if TEMPLATE_STRING_IF_INVALID contains a format string (%s). None means
-# uninitialized.
-invalid_var_format_string = None
-
class TemplateSyntaxError(Exception):
pass
@@ -601,15 +597,14 @@ class FilterExpression(object):
if ignore_failures:
obj = None
else:
- if settings.TEMPLATE_STRING_IF_INVALID:
- global invalid_var_format_string
- if invalid_var_format_string is None:
- invalid_var_format_string = '%s' in settings.TEMPLATE_STRING_IF_INVALID
- if invalid_var_format_string:
- return settings.TEMPLATE_STRING_IF_INVALID % self.var
- return settings.TEMPLATE_STRING_IF_INVALID
+ string_if_invalid = context.engine.string_if_invalid
+ if string_if_invalid:
+ if '%s' in string_if_invalid:
+ return string_if_invalid % self.var
+ else:
+ return string_if_invalid
else:
- obj = settings.TEMPLATE_STRING_IF_INVALID
+ obj = string_if_invalid
else:
obj = self.var
for func, args in self.filters:
@@ -794,7 +789,7 @@ class Variable(object):
if getattr(current, 'do_not_call_in_templates', False):
pass
elif getattr(current, 'alters_data', False):
- current = settings.TEMPLATE_STRING_IF_INVALID
+ current = context.engine.string_if_invalid
else:
try: # method call (assuming no args required)
current = current()
@@ -802,12 +797,12 @@ class Variable(object):
try:
getcallargs(current)
except TypeError: # arguments *were* required
- current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call
+ current = context.engine.string_if_invalid # invalid method call
else:
raise
except Exception as e:
if getattr(e, 'silent_variable_failure', False):
- current = settings.TEMPLATE_STRING_IF_INVALID
+ current = context.engine.string_if_invalid
else:
raise
diff --git a/django/templatetags/i18n.py b/django/templatetags/i18n.py
index 96560d8068..d9db91a413 100644
--- a/django/templatetags/i18n.py
+++ b/django/templatetags/i18n.py
@@ -149,7 +149,7 @@ class BlockTranslateNode(Node):
result = translation.pgettext(message_context, singular)
else:
result = translation.ugettext(singular)
- default_value = settings.TEMPLATE_STRING_IF_INVALID
+ default_value = context.engine.string_if_invalid
def render_value(key):
if key in context: