Skip to content

Commit

Permalink
Fixes #729 - THUMBNAIL_STORAGES is an alias to Django STORAGES
Browse files Browse the repository at this point in the history
  • Loading branch information
claudep committed Sep 28, 2024
1 parent 606254a commit 1813fba
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changes
=======

Unreleased
==========
* ``THUMBNAIL_STORAGE`` should now be an alias in the Django ``STORAGES`` setting.
The old way of specifying a dotted path to a Storage module is still supported.

12.11.0
=======
* Deprecated ``THUMBNAIL_KVSTORE``. Only the Django cache-based store will be
Expand Down
6 changes: 4 additions & 2 deletions docs/reference/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,11 @@ Only applicable for the convert Engine.
``THUMBNAIL_STORAGE``
=====================

- Default: ``settings.DEFAULT_FILE_STORAGE``
- Default: ``default``

The storage class to use for the generated thumbnails.
The storage to use for the generated thumbnails, as an alias from the Django
``STORAGES`` setting.
Optionally accepts a path to a Storage subclass.


``THUMBNAIL_REDIS_URL``
Expand Down
6 changes: 2 additions & 4 deletions sorl/thumbnail/conf/defaults.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from django.conf import settings

# When True ThumbnailNode.render can raise errors
THUMBNAIL_DEBUG = False

Expand Down Expand Up @@ -30,8 +28,8 @@
THUMBNAIL_VIPSTHUMBNAIL = 'vipsthumbnail'
THUMBNAIL_VIPSHEADER = 'vipsheader'

# Storage for the generated thumbnails
THUMBNAIL_STORAGE = settings.STORAGES['default']['BACKEND']
# Storage for the generated thumbnails, as an alias of the Django STORAGES setting.
THUMBNAIL_STORAGE = 'default'

# Redis settings
THUMBNAIL_REDIS_DB = 0
Expand Down
6 changes: 5 additions & 1 deletion sorl/thumbnail/default.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core.files.storage import storages
from django.utils.functional import LazyObject

from sorl.thumbnail.conf import settings
Expand All @@ -21,7 +22,10 @@ def _setup(self):

class Storage(LazyObject):
def _setup(self):
self._wrapped = get_module_class(settings.THUMBNAIL_STORAGE)()
if "." in settings.THUMBNAIL_STORAGE:
self._wrapped = get_module_class(settings.THUMBNAIL_STORAGE)()
else:
self._wrapped = storages[settings.THUMBNAIL_STORAGE]

Check warning on line 28 in sorl/thumbnail/default.py

View check run for this annotation

Codecov / codecov/patch

sorl/thumbnail/default.py#L28

Added line #L28 was not covered by tests


backend = Backend()
Expand Down
2 changes: 1 addition & 1 deletion sorl/thumbnail/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from urllib.request import Request, urlopen

from django.core.files.base import ContentFile, File
from django.core.files.storage import Storage # , default_storage
from django.core.files.storage import Storage
from django.utils.encoding import force_str
from django.utils.functional import LazyObject, empty

Expand Down

0 comments on commit 1813fba

Please sign in to comment.