diff --git a/easy_thumbnails/storage.py b/easy_thumbnails/storage.py index 58e2867..a0bc91b 100644 --- a/easy_thumbnails/storage.py +++ b/easy_thumbnails/storage.py @@ -1,9 +1,23 @@ -from django.core.files.storage import FileSystemStorage, get_storage_class +from django.core.files.storage import FileSystemStorage, get_storage_class, storages from django.utils.deconstruct import deconstructible from django.utils.functional import LazyObject 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): + return storages[settings.THUMBNAIL_DEFAULT_STORAGE] + + return None + @deconstructible class ThumbnailFileSystemStorage(FileSystemStorage): @@ -22,10 +36,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()