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 May 28, 2024
1 parent 77265b7 commit dd1a5d3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
7 changes: 7 additions & 0 deletions easy_thumbnails/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,15 @@ class Settings(AppSettings):
THUMBNAIL_DEFAULT_STORAGE = (
'easy_thumbnails.storage.ThumbnailFileSystemStorage')
"""
(DEPRECATED)
The default Django storage for *saving* generated thumbnails.
"""

THUMBNAIL_DEFAULT_STORAGE_ALIAS = 'easy_thumbnails'
"""
Django 4.2+: The default Django storage name for *saving* generated thumbnails.
"""

THUMBNAIL_MEDIA_ROOT = ''
"""
Used by easy-thumbnail's default storage to locate where thumbnails are
Expand Down
23 changes: 15 additions & 8 deletions easy_thumbnails/storage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
from django.core.files.storage import FileSystemStorage, get_storage_class
from django.core.files.storage import FileSystemStorage
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.
try:
from django.core.files.storage import storages
return storages[settings.THUMBNAIL_DEFAULT_STORAGE_ALIAS]
except (ImportError, TypeError):
from django.core.files.storage import get_storage_class
storage_class = get_storage_class(settings.THUMBNAIL_DEFAULT_STORAGE)
class ThumbnailDefaultStorage(LazyObject):
def _setup(self):
self._wrapped = storage_class()
return ThumbnailDefaultStorage()


@deconstructible
class ThumbnailFileSystemStorage(FileSystemStorage):
Expand All @@ -22,10 +35,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()
10 changes: 10 additions & 0 deletions easy_thumbnails/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@
'easy_thumbnails.tests.apps.EasyThumbnailsTestConfig',
]


STORAGES = {
"easy_thumbnails": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
}

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
Expand Down

0 comments on commit dd1a5d3

Please sign in to comment.