Code

Ticket #8500: default_admin_site_override.diff

File default_admin_site_override.diff, 1.2 KB (added by oyvind, 6 years ago)
Line 
1diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
2index 81e43a1..5aa26fb 100644
3--- a/django/contrib/admin/sites.py
4+++ b/django/contrib/admin/sites.py
5@@ -402,6 +402,24 @@ class AdminSite(object):
6             'app_list': [app_dict]
7         }, context_instance=template.RequestContext(request))
8 
9+def get_adminsite_class(import_path):
10+    try:
11+        dot = import_path.rindex('.')
12+    except ValueError:
13+        raise ImproperlyConfigured("%s isn't a adminsite class." % import_path)
14+    module, classname = import_path[:dot], import_path[dot+1:]
15+    try:
16+        mod = __import__(module, {}, {}, [''])
17+    except ImportError, e:
18+        raise ImproperlyConfigured('Error importing module %s: "%s"' % (module, e))
19+    try:
20+        return getattr(mod, classname)
21+    except AttributeError:
22+        raise ImproperlyConfigured('The module "%s" does not define a "%s" class.' % (module, classname))
23+
24+default_adminsite = get_adminsite_class( getattr(settings,
25+    'DEFAULT_ADMIN_SITE', 'django.contrib.admin.sites.AdminSite') )
26+
27 # This global object represents the default admin site, for the common case.
28 # You can instantiate AdminSite in your own code to create a custom admin site.
29-site = AdminSite()
30+site = default_adminsite()