summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPreston Timmons <prestontimmons@gmail.com>2015-02-03 15:35:55 -0600
committerTim Graham <timograham@gmail.com>2015-02-04 07:47:28 -0500
commit5bc5ddd8b5d787c5e744efead184d46c55d03687 (patch)
tree3e5e5e092944f98eecb1d987721d28ad0dcc5c04
parent7d363ed43247a80d2b764723e1bf6e0e6da4e82f (diff)
Fixed #24235 -- Removed is_usable attribute from template loaders.
-rw-r--r--django/template/engine.py13
-rw-r--r--django/template/loaders/app_directories.py1
-rw-r--r--django/template/loaders/base.py1
-rw-r--r--django/template/loaders/cached.py1
-rw-r--r--django/template/loaders/eggs.py25
-rw-r--r--django/template/loaders/filesystem.py2
-rw-r--r--django/template/loaders/locmem.py1
-rw-r--r--docs/releases/1.9.txt10
8 files changed, 25 insertions, 29 deletions
diff --git a/django/template/engine.py b/django/template/engine.py
index edd731a46c..b346f41f8b 100644
--- a/django/template/engine.py
+++ b/django/template/engine.py
@@ -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)
diff --git a/django/template/loaders/app_directories.py b/django/template/loaders/app_directories.py
index 00ca56c84a..17e2183bfc 100644
--- a/django/template/loaders/app_directories.py
+++ b/django/template/loaders/app_directories.py
@@ -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):
"""
diff --git a/django/template/loaders/base.py b/django/template/loaders/base.py
index c7060725c7..66c2986343 100644
--- a/django/template/loaders/base.py
+++ b/django/template/loaders/base.py
@@ -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
diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py
index aead14490a..5c53b0a658 100644
--- a/django/template/loaders/cached.py
+++ b/django/template/loaders/cached.py
@@ -11,7 +11,6 @@ from .base import Loader as BaseLoader
class Loader(BaseLoader):
- is_usable = True
def __init__(self, engine, loaders):
self.template_cache = {}
diff --git a/django/template/loaders/eggs.py b/django/template/loaders/eggs.py
index 42b43bab2d..4ced12936f 100644
--- a/django/template/loaders/eggs.py
+++ b/django/template/loaders/eggs.py
@@ -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)
diff --git a/django/template/loaders/filesystem.py b/django/template/loaders/filesystem.py
index 44d814a951..4ca19d2b02 100644
--- a/django/template/loaders/filesystem.py
+++ b/django/template/loaders/filesystem.py
@@ -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
diff --git a/django/template/loaders/locmem.py b/django/template/loaders/locmem.py
index 3085d69258..598907bb71 100644
--- a/django/template/loaders/locmem.py
+++ b/django/template/loaders/locmem.py
@@ -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
diff --git a/docs/releases/1.9.txt b/docs/releases/1.9.txt
index 0ff65dec7f..eee63c6f6d 100644
--- a/docs/releases/1.9.txt
+++ b/docs/releases/1.9.txt
@@ -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
~~~~~~~~~~~~~