symposion_app/symposion/boxes/utils.py

20 lines
593 B
Python
Raw Normal View History

2012-07-10 22:18:48 +00:00
from django.core.exceptions import ImproperlyConfigured
try:
from django.utils.importlib import import_module
except ImportError:
from importlib import import_module
def load_path_attr(path):
i = path.rfind(".")
2014-12-15 22:25:00 +00:00
module, attr = path[:i], path[i + 1:]
2012-07-10 22:18:48 +00:00
try:
mod = import_module(module)
except ImportError, e:
raise ImproperlyConfigured("Error importing %s: '%s'" % (module, e))
try:
attr = getattr(mod, attr)
except AttributeError:
raise ImproperlyConfigured("Module '%s' does not define a '%s'" % (module, attr))
return attr