summaryrefslogtreecommitdiff
path: root/django/contrib/admin/checks.py
diff options
context:
space:
mode:
authorHerman S <hermansc@users.noreply.github.com>2019-03-05 22:22:09 +0100
committerTim Graham <timograham@gmail.com>2019-03-14 20:09:57 -0400
commitf976ab1b117574db78d884c94e549a6b8e4c9f9b (patch)
tree7e92e713389df34aaa3aba50cd78b38e2b8d7b63 /django/contrib/admin/checks.py
parent258110d6cdea5050f8df0bbc9af3fcd9bd342d29 (diff)
Fixed #30237 -- Made Authentication/SessionMiddleware and ModelBackend admin checks allow subclasses.
Diffstat (limited to 'django/contrib/admin/checks.py')
-rw-r--r--django/contrib/admin/checks.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index a5bcc3f6df..76c3bd5657 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -15,6 +15,7 @@ from django.forms.models import (
)
from django.template import engines
from django.template.backends.django import DjangoTemplates
+from django.utils.module_loading import import_string
def _issubclass(cls, classinfo):
@@ -28,6 +29,23 @@ def _issubclass(cls, classinfo):
return False
+def _contains_subclass(class_path, candidate_paths):
+ """
+ Return whether or not a dotted class path (or a subclass of that class) is
+ found in a list of candidate paths.
+ """
+ cls = import_string(class_path)
+ for path in candidate_paths:
+ try:
+ candidate_cls = import_string(path)
+ except ImportError:
+ # ImportErrors are raised elsewhere.
+ continue
+ if _issubclass(candidate_cls, cls):
+ return True
+ return False
+
+
def check_admin_app(app_configs, **kwargs):
from django.contrib.admin.sites import all_sites
errors = []
@@ -72,8 +90,7 @@ def check_dependencies(**kwargs):
else:
if ('django.contrib.auth.context_processors.auth'
not in django_templates_instance.context_processors and
- 'django.contrib.auth.backends.ModelBackend'
- in settings.AUTHENTICATION_BACKENDS):
+ _contains_subclass('django.contrib.auth.backends.ModelBackend', settings.AUTHENTICATION_BACKENDS)):
errors.append(checks.Error(
"'django.contrib.auth.context_processors.auth' must be "
"enabled in DjangoTemplates (TEMPLATES) if using the default "
@@ -88,15 +105,14 @@ def check_dependencies(**kwargs):
"the admin application.",
id='admin.E404',
))
- if ('django.contrib.auth.middleware.AuthenticationMiddleware'
- not in settings.MIDDLEWARE):
+
+ if not _contains_subclass('django.contrib.auth.middleware.AuthenticationMiddleware', settings.MIDDLEWARE):
errors.append(checks.Error(
"'django.contrib.auth.middleware.AuthenticationMiddleware' must "
"be in MIDDLEWARE in order to use the admin application.",
id='admin.E408',
))
- if ('django.contrib.messages.middleware.MessageMiddleware'
- not in settings.MIDDLEWARE):
+ if not _contains_subclass('django.contrib.messages.middleware.MessageMiddleware', settings.MIDDLEWARE):
errors.append(checks.Error(
"'django.contrib.messages.middleware.MessageMiddleware' must "
"be in MIDDLEWARE in order to use the admin application.",