Fixed #1292 -- Fixed potential circular-import problem in template loader. Thanks, Kieran Holland
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2226 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
9789766508
commit
2549b31970
|
@ -24,6 +24,28 @@ from django.core.exceptions import ImproperlyConfigured
|
|||
from django.core.template import Origin, StringOrigin, Template, Context, TemplateDoesNotExist, add_to_builtins
|
||||
from django.conf.settings import TEMPLATE_LOADERS, TEMPLATE_DEBUG
|
||||
|
||||
template_source_loaders = None
|
||||
|
||||
class LoaderOrigin(Origin):
|
||||
def __init__(self, display_name, loader, name, dirs):
|
||||
super(LoaderOrigin, self).__init__(display_name)
|
||||
self.loader, self.loadname, self.dirs = loader, name, dirs
|
||||
|
||||
def reload(self):
|
||||
return self.loader(self.loadname, self.dirs)[0]
|
||||
|
||||
def make_origin(display_name, loader, name, dirs):
|
||||
if TEMPLATE_DEBUG:
|
||||
return LoaderOrigin(display_name, loader, name, dirs)
|
||||
else:
|
||||
return None
|
||||
|
||||
def find_template_source(name, dirs=None):
|
||||
# Calculate template_source_loaders the first time the function is executed
|
||||
# because putting this logic in the module-level namespace may cause
|
||||
# circular import errors. See Django ticket #1292.
|
||||
global template_source_loaders
|
||||
if template_source_loaders is None:
|
||||
template_source_loaders = []
|
||||
for path in TEMPLATE_LOADERS:
|
||||
i = path.rfind('.')
|
||||
|
@ -41,22 +63,6 @@ for path in TEMPLATE_LOADERS:
|
|||
warnings.warn("Your TEMPLATE_LOADERS setting includes %r, but your Python installation doesn't support that type of template loading. Consider removing that line from TEMPLATE_LOADERS." % path)
|
||||
else:
|
||||
template_source_loaders.append(func)
|
||||
|
||||
class LoaderOrigin(Origin):
|
||||
def __init__(self, display_name, loader, name, dirs):
|
||||
super(LoaderOrigin, self).__init__(display_name)
|
||||
self.loader, self.loadname, self.dirs = loader, name, dirs
|
||||
|
||||
def reload(self):
|
||||
return self.loader(self.loadname, self.dirs)[0]
|
||||
|
||||
def make_origin(display_name, loader, name, dirs):
|
||||
if TEMPLATE_DEBUG:
|
||||
return LoaderOrigin(display_name, loader, name, dirs)
|
||||
else:
|
||||
return None
|
||||
|
||||
def find_template_source(name, dirs=None):
|
||||
for loader in template_source_loaders:
|
||||
try:
|
||||
source, display_name = loader(name, dirs)
|
||||
|
|
Loading…
Reference in New Issue