__init__.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. VERSION = (0,6,0)
  2. from xadmin.sites import AdminSite, site
  3. class Settings(object):
  4. pass
  5. def autodiscover():
  6. """
  7. Auto-discover INSTALLED_APPS admin.py modules and fail silently when
  8. not present. This forces an import on them to register any admin bits they
  9. may want.
  10. """
  11. from importlib import import_module
  12. from django.conf import settings
  13. from django.utils.module_loading import module_has_submodule
  14. from django.apps import apps
  15. setattr(settings, 'CRISPY_TEMPLATE_PACK', 'bootstrap3')
  16. setattr(settings, 'CRISPY_CLASS_CONVERTERS', {
  17. "textinput": "textinput textInput form-control",
  18. "fileinput": "fileinput fileUpload form-control",
  19. "passwordinput": "textinput textInput form-control",
  20. })
  21. from xadmin.views import register_builtin_views
  22. register_builtin_views(site)
  23. # load xadmin settings from XADMIN_CONF module
  24. try:
  25. xadmin_conf = getattr(settings, 'XADMIN_CONF', 'xadmin_conf.py')
  26. conf_mod = import_module(xadmin_conf)
  27. except Exception:
  28. conf_mod = None
  29. if conf_mod:
  30. for key in dir(conf_mod):
  31. setting = getattr(conf_mod, key)
  32. try:
  33. if issubclass(setting, Settings):
  34. site.register_settings(setting.__name__, setting)
  35. except Exception:
  36. pass
  37. from xadmin.plugins import register_builtin_plugins
  38. register_builtin_plugins(site)
  39. for app_config in apps.get_app_configs():
  40. mod = import_module(app_config.name)
  41. # Attempt to import the app's admin module.
  42. try:
  43. before_import_registry = site.copy_registry()
  44. import_module('%s.adminx' % app_config.name)
  45. except:
  46. # Reset the model registry to the state before the last import as
  47. # this import will have to reoccur on the next request and this
  48. # could raise NotRegistered and AlreadyRegistered exceptions
  49. # (see #8245).
  50. site.restore_registry(before_import_registry)
  51. # Decide whether to bubble up this error. If the app just
  52. # doesn't have an admin module, we can ignore the error
  53. # attempting to import it, otherwise we want it to bubble up.
  54. if module_has_submodule(mod, 'adminx'):
  55. raise
  56. default_app_config = 'xadmin.apps.XAdminConfig'