Fixed #24235 -- Removed is_usable attribute from template loaders.

This commit is contained in:
Preston Timmons 2015-02-03 15:35:55 -06:00 committed by Tim Graham
parent 7d363ed432
commit 5bc5ddd8b5
8 changed files with 25 additions and 29 deletions

View File

@ -121,18 +121,7 @@ class Engine(object):
"instead of django.template.loaders.base.Loader. " %
loader, RemovedInDjango20Warning, stacklevel=2)
loader_instance = loader_class(*args)
if not loader_instance.is_usable:
warnings.warn(
"Your template loaders configuration includes %r, but "
"your Python installation doesn't support that type of "
"template loading. Consider removing that line from "
"your settings." % loader)
return None
else:
return loader_instance
return loader_class(*args)
else:
raise ImproperlyConfigured(
"Invalid value in template loaders configuration: %r" % loader)

View File

@ -14,7 +14,6 @@ from .base import Loader as BaseLoader
class Loader(BaseLoader):
is_usable = True
def get_template_sources(self, template_name, template_dirs=None):
"""

View File

@ -2,7 +2,6 @@ from django.template.base import Template, TemplateDoesNotExist
class Loader(object):
is_usable = False
# Only used to raise a deprecation warning. Remove in Django 2.0.
_accepts_engine_in_init = True

View File

@ -11,7 +11,6 @@ from .base import Loader as BaseLoader
class Loader(BaseLoader):
is_usable = True
def __init__(self, engine, loaders):
self.template_cache = {}

View File

@ -14,7 +14,11 @@ from .base import Loader as BaseLoader
class Loader(BaseLoader):
is_usable = resource_string is not None
def __init__(self, engine):
if resource_string is None:
raise RuntimeError("Setuptools must be installed to use the egg loader")
super(Loader, self).__init__(engine)
def load_template_source(self, template_name, template_dirs=None):
"""
@ -22,14 +26,13 @@ class Loader(BaseLoader):
For every installed app, it tries to get the resource (app, template_name).
"""
if resource_string is not None:
pkg_name = 'templates/' + template_name
for app_config in apps.get_app_configs():
try:
resource = resource_string(app_config.name, pkg_name)
except Exception:
continue
if six.PY2:
resource = resource.decode(self.engine.file_charset)
return (resource, 'egg:%s:%s' % (app_config.name, pkg_name))
pkg_name = 'templates/' + template_name
for app_config in apps.get_app_configs():
try:
resource = resource_string(app_config.name, pkg_name)
except Exception:
continue
if six.PY2:
resource = resource.decode(self.engine.file_charset)
return (resource, 'egg:%s:%s' % (app_config.name, pkg_name))
raise TemplateDoesNotExist(template_name)

View File

@ -12,7 +12,6 @@ from .base import Loader as BaseLoader
class Loader(BaseLoader):
is_usable = True
def get_template_sources(self, template_name, template_dirs=None):
"""
@ -44,4 +43,3 @@ class Loader(BaseLoader):
error_msg = ("Your template directories configuration is empty. "
"Change it to point to at least one template directory.")
raise TemplateDoesNotExist(error_msg)
load_template_source.is_usable = True

View File

@ -8,7 +8,6 @@ from .base import Loader as BaseLoader
class Loader(BaseLoader):
is_usable = True
def __init__(self, engine, templates_dict):
self.templates_dict = templates_dict

View File

@ -182,6 +182,16 @@ Default settings that were tuples are now lists
The default settings in ``django.conf.global_settings`` were a combination of
lists and tuples. All settings that were formerly tuples are now lists.
``is_usable`` attribute on template loaders is removed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Django template loaders previously required an ``is_usable`` attribute to be
defined. If a loader was configured in the template settings and this attribute
was ``False``, the loader would be silently ignored. In practice, this was only
used by the egg loader to detect if setuptools was installed. The ``is_usable``
attribute is now removed and the egg loader instead fails at runtime if
setuptools is not installed.
Miscellaneous
~~~~~~~~~~~~~