summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-01-11 19:06:36 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-01-12 21:01:34 +0100
commit3bba4b420ed5e89608d9d71ad328fbaed026b232 (patch)
tree5b319cfe056030e4526935091b03eda69f6290f6
parent6b5113ec94e6b9c81e3e4d9a68b0703ccb14c22d (diff)
Avoided exceptions in a non-critical check in the admin.
This change makes it possible to configure several Django template engines in a project and still use the admin. On the flip side the check is silently skipped when no Django template engine is configured.
-rw-r--r--django/contrib/admin/sites.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index 6c6f35f813..ab0ec1a837 100644
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -168,14 +168,25 @@ class AdminSite(object):
installed, as well as the auth context processor.
"""
if not apps.is_installed('django.contrib.admin'):
- raise ImproperlyConfigured("Put 'django.contrib.admin' in "
- "your INSTALLED_APPS setting in order to use the admin application.")
+ raise ImproperlyConfigured(
+ "Put 'django.contrib.admin' in your INSTALLED_APPS "
+ "setting in order to use the admin application.")
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 Engine.get_default().context_processors:
- raise ImproperlyConfigured("Enable 'django.contrib.auth.context_processors.auth' "
- "in your TEMPLATES setting in order to use the admin application.")
+ raise ImproperlyConfigured(
+ "Put 'django.contrib.contenttypes' in your INSTALLED_APPS "
+ "setting in order to use the admin application.")
+ try:
+ default_template_engine = Engine.get_default()
+ except ImproperlyConfigured:
+ # Skip the check if the user has a non-trivial TEMPLATES setting
+ pass
+ else:
+ if ('django.contrib.auth.context_processors.auth'
+ not in default_template_engine.context_processors):
+ raise ImproperlyConfigured(
+ "Enable 'django.contrib.auth.context_processors.auth' "
+ "in your TEMPLATES setting in order to use the admin "
+ "application.")
def admin_view(self, view, cacheable=False):
"""