diff --git a/easy_thumbnails/storage.py b/easy_thumbnails/storage.py index 58e2867e..0e29c244 100644 --- a/easy_thumbnails/storage.py +++ b/easy_thumbnails/storage.py @@ -4,6 +4,21 @@ from easy_thumbnails.conf import settings +def get_storage(): + # If the user has specified a custom storage backend, use it. + if getattr(settings, "THUMBNAIL_DEFAULT_STORAGE", None): + try: + storage_class = get_storage_class(settings.THUMBNAIL_DEFAULT_STORAGE) + class ThumbnailDefaultStorage(LazyObject): + def _setup(self): + self._wrapped = storage_class() + return ThumbnailDefaultStorage() + except (ImportError, TypeError): + from django.core.files.storage import storages + return storages[settings.THUMBNAIL_DEFAULT_STORAGE] + + return None + @deconstructible class ThumbnailFileSystemStorage(FileSystemStorage): @@ -22,10 +37,4 @@ def __init__(self, location=None, base_url=None, *args, **kwargs): super().__init__(location, base_url, *args, **kwargs) -class ThumbnailDefaultStorage(LazyObject): - def _setup(self): - self._wrapped = get_storage_class( - settings.THUMBNAIL_DEFAULT_STORAGE)() - - -thumbnail_default_storage = ThumbnailDefaultStorage() +thumbnail_default_storage = get_storage()