diff --git a/formtools/tests/wizard/loadstorage.py b/formtools/tests/wizard/loadstorage.py index 267dee0..bb0b06e 100644 --- a/formtools/tests/wizard/loadstorage.py +++ b/formtools/tests/wizard/loadstorage.py @@ -1,8 +1,6 @@ from django.test import TestCase -from django.contrib.formtools.wizard.storage import (get_storage, - MissingStorageModule, - MissingStorageClass) +from django.contrib.formtools.wizard.storage import get_storage, MissingStorage from django.contrib.formtools.wizard.storage.base import BaseStorage @@ -12,11 +10,9 @@ class TestLoadStorage(TestCase): type(get_storage('django.contrib.formtools.wizard.storage.base.BaseStorage', 'wizard1')), BaseStorage) - def test_missing_module(self): - self.assertRaises(MissingStorageModule, get_storage, + def test_missing_storage(self): + self.assertRaises(MissingStorage, get_storage, 'django.contrib.formtools.wizard.storage.idontexist.IDontExistStorage', 'wizard1') - - def test_missing_class(self): - self.assertRaises(MissingStorageClass, get_storage, + self.assertRaises(MissingStorage, get_storage, 'django.contrib.formtools.wizard.storage.base.IDontExistStorage', 'wizard1') diff --git a/formtools/wizard/storage/__init__.py b/formtools/wizard/storage/__init__.py index f2293c9..8f57605 100644 --- a/formtools/wizard/storage/__init__.py +++ b/formtools/wizard/storage/__init__.py @@ -1,22 +1,14 @@ -from django.utils.importlib import import_module +from django.core.exceptions import ImproperlyConfigured +from django.utils.module_loading import import_by_path from django.contrib.formtools.wizard.storage.base import BaseStorage from django.contrib.formtools.wizard.storage.exceptions import ( - MissingStorageModule, MissingStorageClass, NoFileStorageConfigured) + MissingStorage, NoFileStorageConfigured) def get_storage(path, *args, **kwargs): - i = path.rfind('.') - module, attr = path[:i], path[i+1:] try: - mod = import_module(module) - except ImportError as e: - raise MissingStorageModule( - 'Error loading storage %s: "%s"' % (module, e)) - try: - storage_class = getattr(mod, attr) - except AttributeError: - raise MissingStorageClass( - 'Module "%s" does not define a storage named "%s"' % (module, attr)) + storage_class = import_by_path(path) + except ImproperlyConfigured as e: + raise MissingStorage('Error loading storage: %s' % e) return storage_class(*args, **kwargs) - diff --git a/formtools/wizard/storage/exceptions.py b/formtools/wizard/storage/exceptions.py index eab9030..e273a86 100644 --- a/formtools/wizard/storage/exceptions.py +++ b/formtools/wizard/storage/exceptions.py @@ -1,9 +1,6 @@ from django.core.exceptions import ImproperlyConfigured -class MissingStorageModule(ImproperlyConfigured): - pass - -class MissingStorageClass(ImproperlyConfigured): +class MissingStorage(ImproperlyConfigured): pass class NoFileStorageConfigured(ImproperlyConfigured):