summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMosson, Andrew <mossona@advisory.com>2014-12-14 05:22:37 +0200
committerTim Graham <timograham@gmail.com>2014-12-17 09:16:05 -0500
commit6d8c14621e2878ea2051ee56326c66969a1d18d0 (patch)
tree8fa26c3e3421b070f45cc7316fb1a7f80761a1f4
parenta38951948a62c0d51a8b50a599f17e590f750bf5 (diff)
[1.7x.] Fixed #23497 -- Made admin system checks run for custom AdminSites.
Backport of b7219c7ba5fdfbf9349948b5a91af50e32822ee6 from master
-rw-r--r--django/contrib/admin/checks.py7
-rw-r--r--django/contrib/admin/sites.py4
-rw-r--r--docs/releases/1.7.2.txt2
-rw-r--r--tests/admin_checks/tests.py30
4 files changed, 31 insertions, 12 deletions
diff --git a/django/contrib/admin/checks.py b/django/contrib/admin/checks.py
index 335062562d..334c33839e 100644
--- a/django/contrib/admin/checks.py
+++ b/django/contrib/admin/checks.py
@@ -11,12 +11,9 @@ from django.forms.models import BaseModelForm, _get_foreign_key, BaseModelFormSe
def check_admin_app(**kwargs):
- from django.contrib.admin.sites import site
+ from django.contrib.admin.sites import system_check_errors
- return list(chain.from_iterable(
- model_admin.check(model, **kwargs)
- for model, model_admin in site._registry.items()
- ))
+ return system_check_errors
class BaseModelAdminChecks(object):
diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
index efac3c7521..b6df3fa5fc 100644
--- a/django/contrib/admin/sites.py
+++ b/django/contrib/admin/sites.py
@@ -14,6 +14,8 @@ from django.utils.translation import ugettext_lazy, ugettext as _
from django.views.decorators.cache import never_cache
from django.conf import settings
+system_check_errors = []
+
class AlreadyRegistered(Exception):
pass
@@ -96,7 +98,7 @@ class AdminSite(object):
admin_class = type("%sAdmin" % model.__name__, (admin_class,), options)
if admin_class is not ModelAdmin and settings.DEBUG:
- admin_class.check(model)
+ system_check_errors.extend(admin_class.check(model))
# Instantiate the admin class to save in the registry
self._registry[model] = admin_class(model, self)
diff --git a/docs/releases/1.7.2.txt b/docs/releases/1.7.2.txt
index 860c819525..88f3d3e1d8 100644
--- a/docs/releases/1.7.2.txt
+++ b/docs/releases/1.7.2.txt
@@ -149,3 +149,5 @@ Bugfixes
* Restored the ``pre_migrate`` signal if all apps have migrations
(:ticket:`23975`).
+
+* Made admin system checks run for custom ``AdminSite``\s (:ticket:`23497`).
diff --git a/tests/admin_checks/tests.py b/tests/admin_checks/tests.py
index 799fc2899a..51eec7a388 100644
--- a/tests/admin_checks/tests.py
+++ b/tests/admin_checks/tests.py
@@ -7,7 +7,7 @@ from django.contrib import admin
from django.contrib.contenttypes.admin import GenericStackedInline
from django.core import checks
from django.core.exceptions import ImproperlyConfigured
-from django.test import TestCase
+from django.test import override_settings, TestCase
from .models import Song, Book, Album, TwoAlbumFKAndAnE, City, State, Influence
@@ -34,14 +34,16 @@ class ValidFormFieldsets(admin.ModelAdmin):
)
+class MyAdmin(admin.ModelAdmin):
+ @classmethod
+ def check(cls, model, **kwargs):
+ return ['error!']
+
+
class SystemChecksTestCase(TestCase):
+ @override_settings(DEBUG=True)
def test_checks_are_performed(self):
- class MyAdmin(admin.ModelAdmin):
- @classmethod
- def check(self, model, **kwargs):
- return ['error!']
-
admin.site.register(Song, MyAdmin)
try:
errors = checks.run_checks()
@@ -49,6 +51,22 @@ class SystemChecksTestCase(TestCase):
self.assertEqual(errors, expected)
finally:
admin.site.unregister(Song)
+ admin.sites.system_check_errors = []
+
+ @override_settings(DEBUG=True)
+ def test_custom_adminsite(self):
+ class CustomAdminSite(admin.AdminSite):
+ pass
+
+ custom_site = CustomAdminSite()
+ custom_site.register(Song, MyAdmin)
+ try:
+ errors = checks.run_checks()
+ expected = ['error!']
+ self.assertEqual(errors, expected)
+ finally:
+ custom_site.unregister(Song)
+ admin.sites.system_check_errors = []
def test_readonly_and_editable(self):
class SongAdmin(admin.ModelAdmin):