Removed some uses of global APIs from django.template.loader.

This commit is contained in:
Aymeric Augustin 2014-11-27 23:02:46 +01:00
parent 332154e726
commit 24dffaf0cb
4 changed files with 6 additions and 10 deletions

View File

@ -1264,13 +1264,12 @@ class Library(object):
_dict = func(*resolved_args, **resolved_kwargs)
if not getattr(self, 'nodelist', False):
from django.template.loader import get_template, select_template
if isinstance(file_name, Template):
t = file_name
elif not isinstance(file_name, six.string_types) and is_iterable(file_name):
t = select_template(file_name)
t = context.engine.select_template(file_name)
else:
t = get_template(file_name)
t = context.engine.get_template(file_name)
self.nodelist = t.nodelist
new_context = context_class(_dict, **{
'autoescape': context.autoescape,

View File

@ -2,7 +2,6 @@ from collections import defaultdict
from django.template.base import TemplateSyntaxError, Library, Node, TextNode,\
token_kwargs, Variable
from django.template.loader import get_template
from django.utils.safestring import mark_safe
from django.utils import six
@ -102,7 +101,7 @@ class ExtendsNode(Node):
raise TemplateSyntaxError(error_msg)
if hasattr(parent, 'render'):
return parent # parent is a Template object
return get_template(parent)
return context.engine.get_template(parent)
def render(self, context):
compiled_parent = self.get_parent(context)
@ -143,7 +142,7 @@ class IncludeNode(Node):
# Does this quack like a Template?
if not callable(getattr(template, 'render', None)):
# If not, we'll try get_template
template = get_template(template)
template = context.engine.get_template(template)
values = {
name: var.resolve(context)
for name, var in six.iteritems(self.extra_context)

View File

@ -1,5 +1,4 @@
from django.template.base import TemplateDoesNotExist
from django.template.loader import get_template_from_string
class Loader(object):
@ -21,7 +20,7 @@ class Loader(object):
template_name, template_dirs)
try:
template = get_template_from_string(source, origin, template_name)
template = self.engine.from_string(source, origin, template_name)
except TemplateDoesNotExist:
# If compiling the template we found raises TemplateDoesNotExist,
# back off to returning the source and display name for the

View File

@ -5,7 +5,6 @@ to load templates from them in order, caching the result.
import hashlib
from django.template.base import TemplateDoesNotExist
from django.template.loader import get_template_from_string
from django.utils.encoding import force_bytes
from .base import Loader as BaseLoader
@ -62,7 +61,7 @@ class Loader(BaseLoader):
template, origin = self.find_template(template_name, template_dirs)
if not hasattr(template, 'render'):
try:
template = get_template_from_string(template, origin, template_name)
template = self.engine.from_string(template, origin, template_name)
except TemplateDoesNotExist:
# If compiling the template we found raises TemplateDoesNotExist,
# back off to returning the source and display name for the template