2010-10-27 15:08:15 +08:00
|
|
|
# ACTION_CHECKBOX_NAME is unused, but should stay since its import from here
|
|
|
|
# has been referenced in documentation.
|
|
|
|
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
|
2008-07-19 07:54:34 +08:00
|
|
|
from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
|
|
|
|
from django.contrib.admin.options import StackedInline, TabularInline
|
|
|
|
from django.contrib.admin.sites import AdminSite, site
|
2011-05-03 18:44:23 +08:00
|
|
|
from django.contrib.admin.filters import (ListFilter, SimpleListFilter,
|
|
|
|
FieldListFilter, BooleanFieldListFilter, RelatedFieldListFilter,
|
|
|
|
ChoicesFieldListFilter, DateFieldListFilter, AllValuesFieldListFilter)
|
2008-07-19 07:54:34 +08:00
|
|
|
|
2008-12-24 02:25:24 +08:00
|
|
|
|
2008-07-19 07:54:34 +08:00
|
|
|
def autodiscover():
|
|
|
|
"""
|
2008-12-24 02:25:24 +08:00
|
|
|
Auto-discover INSTALLED_APPS admin.py modules and fail silently when
|
2008-07-19 07:54:34 +08:00
|
|
|
not present. This forces an import on them to register any admin bits they
|
|
|
|
may want.
|
|
|
|
"""
|
2008-12-24 02:25:24 +08:00
|
|
|
|
2010-04-12 22:36:48 +08:00
|
|
|
import copy
|
2013-07-29 21:50:58 +08:00
|
|
|
from importlib import import_module
|
2008-07-19 07:54:34 +08:00
|
|
|
from django.conf import settings
|
2010-04-16 06:32:53 +08:00
|
|
|
from django.utils.module_loading import module_has_submodule
|
2008-08-27 00:18:20 +08:00
|
|
|
|
2008-07-19 07:54:34 +08:00
|
|
|
for app in settings.INSTALLED_APPS:
|
2010-01-11 02:56:53 +08:00
|
|
|
mod = import_module(app)
|
2010-04-16 06:32:53 +08:00
|
|
|
# Attempt to import the app's admin module.
|
2010-04-12 22:36:48 +08:00
|
|
|
try:
|
|
|
|
before_import_registry = copy.copy(site._registry)
|
|
|
|
import_module('%s.admin' % app)
|
|
|
|
except:
|
|
|
|
# Reset the model registry to the state before the last import as
|
|
|
|
# this import will have to reoccur on the next request and this
|
|
|
|
# could raise NotRegistered and AlreadyRegistered exceptions
|
|
|
|
# (see #8245).
|
|
|
|
site._registry = before_import_registry
|
2010-04-16 06:32:53 +08:00
|
|
|
|
|
|
|
# Decide whether to bubble up this error. If the app just
|
|
|
|
# doesn't have an admin module, we can ignore the error
|
|
|
|
# attempting to import it, otherwise we want it to bubble up.
|
|
|
|
if module_has_submodule(mod, 'admin'):
|
|
|
|
raise
|