Simplify TMP_STORAGE_CLASS importing

Reuse Django's import_string(); avoid reimplementing it.
This commit is contained in:
Jon Dufresne 2018-11-04 16:47:48 -08:00
parent ec568b5ad9
commit 3746b20348
1 changed files with 2 additions and 9 deletions

View File

@ -22,6 +22,7 @@ except ImportError: # Django<2.0
from django.conf import settings
from django.template.defaultfilters import pluralize
from django.utils.decorators import method_decorator
from django.utils.module_loading import import_string
from django.views.decorators.http import require_POST
from .forms import (
@ -49,15 +50,7 @@ TMP_STORAGE_CLASS = getattr(settings, 'IMPORT_EXPORT_TMP_STORAGE_CLASS',
if isinstance(TMP_STORAGE_CLASS, six.string_types):
try:
# Nod to tastypie's use of importlib.
parts = TMP_STORAGE_CLASS.split('.')
module_path, class_name = '.'.join(parts[:-1]), parts[-1]
module = importlib.import_module(module_path)
TMP_STORAGE_CLASS = getattr(module, class_name)
except ImportError as e:
msg = "Could not import '%s' for import_export setting 'IMPORT_EXPORT_TMP_STORAGE_CLASS'" % TMP_STORAGE_CLASS
raise ImportError(msg)
TMP_STORAGE_CLASS = import_string(TMP_STORAGE_CLASS)
class ImportExportMixinBase(object):