Ticket #8500: default_admin_site_override.diff

File default_admin_site_override.diff, 1.2 KB (added by oyvind, 7 years ago)
  • django/contrib/admin/sites.py

    diff --git a/django/contrib/admin/sites.py b/django/contrib/admin/sites.py
    index 81e43a1..5aa26fb 100644
    a b class AdminSite(object): 
    402402            'app_list': [app_dict]
    403403        }, context_instance=template.RequestContext(request))
    404404
     405def get_adminsite_class(import_path):
     406    try:
     407        dot = import_path.rindex('.')
     408    except ValueError:
     409        raise ImproperlyConfigured("%s isn't a adminsite class." % import_path)
     410    module, classname = import_path[:dot], import_path[dot+1:]
     411    try:
     412        mod = __import__(module, {}, {}, [''])
     413    except ImportError, e:
     414        raise ImproperlyConfigured('Error importing module %s: "%s"' % (module, e))
     415    try:
     416        return getattr(mod, classname)
     417    except AttributeError:
     418        raise ImproperlyConfigured('The module "%s" does not define a "%s" class.' % (module, classname))
     419
     420default_adminsite = get_adminsite_class( getattr(settings,
     421    'DEFAULT_ADMIN_SITE', 'django.contrib.admin.sites.AdminSite') )
     422
    405423# This global object represents the default admin site, for the common case.
    406424# You can instantiate AdminSite in your own code to create a custom admin site.
    407 site = AdminSite()
     425site = default_adminsite()
Back to Top