__init__.py 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. from django.conf import settings
  2. from django.core.exceptions import ImproperlyConfigured
  3. from django.utils.importlib import import_module
  4. def get_storage(import_path):
  5. """
  6. Imports the message storage class described by import_path, where
  7. import_path is the full Python path to the class.
  8. """
  9. try:
  10. dot = import_path.rindex('.')
  11. except ValueError:
  12. raise ImproperlyConfigured("%s isn't a Python path." % import_path)
  13. module, classname = import_path[:dot], import_path[dot + 1:]
  14. try:
  15. mod = import_module(module)
  16. except ImportError, e:
  17. raise ImproperlyConfigured('Error importing module %s: "%s"' %
  18. (module, e))
  19. try:
  20. return getattr(mod, classname)
  21. except AttributeError:
  22. raise ImproperlyConfigured('Module "%s" does not define a "%s" '
  23. 'class.' % (module, classname))
  24. # Callable with the same interface as the storage classes i.e. accepts a
  25. # 'request' object. It is wrapped in a lambda to stop 'settings' being used at
  26. # the module level
  27. default_storage = lambda request: get_storage(settings.MESSAGE_STORAGE)(request)