Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for Django 4.2 storages #626

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions easy_thumbnails/conf.py
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_NAME = '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
26 changes: 18 additions & 8 deletions easy_thumbnails/storage.py
@@ -1,9 +1,25 @@
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.
if getattr(settings, "THUMBNAIL_DEFAULT_STORAGE", None):
try:
from django.core.files.storage import storages
return storages[settings.THUMBNAIL_DEFAULT_STORAGE_NAME]
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()

return None


@deconstructible
class ThumbnailFileSystemStorage(FileSystemStorage):
Expand All @@ -22,10 +38,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
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