From df374678669f5c857c8657abe3712ee3d64acc1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Dlouh=C3=BD?= Date: Thu, 16 Nov 2023 15:55:50 +0100 Subject: [PATCH] add support for Django 4.2 storages --- easy_thumbnails/storage.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) 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()