Moved make_origin into the Engine class.
This commit is contained in:
parent
240ea67ce0
commit
246cfdeae3
|
@ -105,12 +105,11 @@ class Engine(object):
|
|||
"Invalid value in template loaders configuration: %r" % loader)
|
||||
|
||||
def find_template(self, name, dirs=None):
|
||||
# Inner import to avoid circular dependency
|
||||
from .loader import make_origin
|
||||
for loader in self.template_loaders:
|
||||
try:
|
||||
source, display_name = loader(name, dirs)
|
||||
return (source, make_origin(display_name, loader, name, dirs))
|
||||
origin = self.make_origin(display_name, loader, name, dirs)
|
||||
return source, origin
|
||||
except TemplateDoesNotExist:
|
||||
pass
|
||||
raise TemplateDoesNotExist(name)
|
||||
|
@ -214,3 +213,11 @@ class Engine(object):
|
|||
tokens = lexer.tokenize()
|
||||
parser = parser_class(tokens)
|
||||
return parser.parse()
|
||||
|
||||
def make_origin(self, display_name, loader, name, dirs):
|
||||
if settings.TEMPLATE_DEBUG and display_name:
|
||||
# Inner import to avoid circular dependency
|
||||
from .loader import LoaderOrigin
|
||||
return LoaderOrigin(display_name, loader, name, dirs)
|
||||
else:
|
||||
return None
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.deprecation import RemovedInDjango20Warning
|
||||
|
||||
from .base import Origin
|
||||
|
@ -16,13 +15,6 @@ class LoaderOrigin(Origin):
|
|||
return self.loader(self.loadname, self.dirs)[0]
|
||||
|
||||
|
||||
def make_origin(display_name, loader, name, dirs):
|
||||
if settings.TEMPLATE_DEBUG and display_name:
|
||||
return LoaderOrigin(display_name, loader, name, dirs)
|
||||
else:
|
||||
return None
|
||||
|
||||
|
||||
def find_template(*args, **kwargs):
|
||||
return Engine.get_default().find_template(*args, **kwargs)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django.template.base import TemplateDoesNotExist
|
||||
from django.template.loader import get_template_from_string, make_origin
|
||||
from django.template.loader import get_template_from_string
|
||||
|
||||
|
||||
class Loader(object):
|
||||
|
@ -16,7 +16,7 @@ class Loader(object):
|
|||
def load_template(self, template_name, template_dirs=None):
|
||||
source, display_name = self.load_template_source(
|
||||
template_name, template_dirs)
|
||||
origin = make_origin(
|
||||
origin = self.engine.make_origin(
|
||||
display_name, self.load_template_source,
|
||||
template_name, template_dirs)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ 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, make_origin
|
||||
from django.template.loader import get_template_from_string
|
||||
from django.utils.encoding import force_bytes
|
||||
|
||||
from .base import Loader as BaseLoader
|
||||
|
@ -42,7 +42,8 @@ class Loader(BaseLoader):
|
|||
except TemplateDoesNotExist:
|
||||
pass
|
||||
else:
|
||||
result = (template, make_origin(display_name, loader, name, dirs))
|
||||
origin = self.engine.make_origin(display_name, loader, name, dirs)
|
||||
result = template, origin
|
||||
break
|
||||
self.find_template_cache[key] = result
|
||||
if result:
|
||||
|
|
Loading…
Reference in New Issue