From 18533fb558f66377c42bbbab672503253d3668d1 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 22 Nov 2014 21:43:13 +0100 Subject: [PATCH] Removed direct references to template-related settings. --- django/contrib/admin/sites.py | 3 ++- django/contrib/admindocs/views.py | 5 +++-- django/views/debug.py | 8 +++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py index 02859c120f2..e310635eeaf 100644 --- a/django/contrib/admin/sites.py +++ b/django/contrib/admin/sites.py @@ -7,6 +7,7 @@ from django.db.models.base import ModelBase from django.apps import apps from django.core.exceptions import ImproperlyConfigured, PermissionDenied from django.core.urlresolvers import reverse, NoReverseMatch +from django.template.engine import Engine from django.template.response import TemplateResponse from django.utils import six from django.utils.text import capfirst @@ -170,7 +171,7 @@ class AdminSite(object): if not apps.is_installed('django.contrib.contenttypes'): raise ImproperlyConfigured("Put 'django.contrib.contenttypes' in " "your INSTALLED_APPS setting in order to use the admin application.") - if 'django.contrib.auth.context_processors.auth' not in settings.TEMPLATE_CONTEXT_PROCESSORS: + if 'django.contrib.auth.context_processors.auth' not in Engine.get_default().context_processors: raise ImproperlyConfigured("Put 'django.contrib.auth.context_processors.auth' " "in your TEMPLATE_CONTEXT_PROCESSORS setting in order to use the admin application.") diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py index f4a49431f6d..1768fd72c91 100644 --- a/django/contrib/admindocs/views.py +++ b/django/contrib/admindocs/views.py @@ -13,6 +13,7 @@ from django.core.exceptions import ViewDoesNotExist from django.http import Http404 from django.core import urlresolvers from django.contrib.admindocs import utils +from django.template.engine import Engine from django.utils.decorators import method_decorator from django.utils._os import upath from django.utils import six @@ -291,13 +292,13 @@ class TemplateDetailView(BaseAdminDocsView): def get_context_data(self, **kwargs): template = self.kwargs['template'] templates = [] - for dir in settings.TEMPLATE_DIRS: + for dir in Engine.get_default().dirs: template_file = os.path.join(dir, template) templates.append({ 'file': template_file, 'exists': os.path.exists(template_file), 'contents': lambda: open(template_file).read() if os.path.exists(template_file) else '', - 'order': list(settings.TEMPLATE_DIRS).index(dir), + 'order': list(Engine.get_default().dirs).index(dir), }) kwargs.update({ 'name': template, diff --git a/django/views/debug.py b/django/views/debug.py index ab32d866a54..55f9b231eaf 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -276,14 +276,16 @@ class ExceptionReporter(object): def get_traceback_data(self): """Return a dictionary containing traceback information.""" + # TODO: handle multiple template engines. + template_engine = Engine.get_default() + if self.exc_type and issubclass(self.exc_type, TemplateDoesNotExist): self.template_does_not_exist = True self.loader_debug_info = [] # If Django fails in get_template_loaders, provide an empty list # for the following loop to not fail. try: - # TODO: handle multiple template engines. - template_loaders = Engine.get_default().template_loaders + template_loaders = template_engine.template_loaders except Exception: template_loaders = [] for loader in template_loaders: @@ -302,7 +304,7 @@ class ExceptionReporter(object): 'loader': loader_name, 'templates': template_list, }) - if (settings.TEMPLATE_DEBUG and + if (template_engine.debug and hasattr(self.exc_value, 'django_template_source')): self.get_template_exception_info()