/django/contrib/admin/__init__.py

https://code.google.com/p/mango-py/ · Python · 38 lines · 18 code · 5 blank · 15 comment · 3 complexity · 5a58b8f61e1c67c935d998869bb36909 MD5 · raw file

  1. # ACTION_CHECKBOX_NAME is unused, but should stay since its import from here
  2. # has been referenced in documentation.
  3. from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
  4. from django.contrib.admin.options import ModelAdmin, HORIZONTAL, VERTICAL
  5. from django.contrib.admin.options import StackedInline, TabularInline
  6. from django.contrib.admin.sites import AdminSite, site
  7. def autodiscover():
  8. """
  9. Auto-discover INSTALLED_APPS admin.py modules and fail silently when
  10. not present. This forces an import on them to register any admin bits they
  11. may want.
  12. """
  13. import copy
  14. from django.conf import settings
  15. from django.utils.importlib import import_module
  16. from django.utils.module_loading import module_has_submodule
  17. for app in settings.INSTALLED_APPS:
  18. mod = import_module(app)
  19. # Attempt to import the app's admin module.
  20. try:
  21. before_import_registry = copy.copy(site._registry)
  22. import_module('%s.admin' % app)
  23. except:
  24. # Reset the model registry to the state before the last import as
  25. # this import will have to reoccur on the next request and this
  26. # could raise NotRegistered and AlreadyRegistered exceptions
  27. # (see #8245).
  28. site._registry = before_import_registry
  29. # Decide whether to bubble up this error. If the app just
  30. # doesn't have an admin module, we can ignore the error
  31. # attempting to import it, otherwise we want it to bubble up.
  32. if module_has_submodule(mod, 'admin'):
  33. raise