Skip to content

Commit

Permalink
add support for Django 4.2 storages
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Nov 16, 2023
1 parent 77265b7 commit da1082c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions 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):
Expand All @@ -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()

0 comments on commit da1082c

Please sign in to comment.