diff --git a/CHANGES.rst b/CHANGES.rst index 37748df2f..b9e794ef5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 diff --git a/docs/reference/settings.rst b/docs/reference/settings.rst index 3988f6ad2..14b26da1e 100644 --- a/docs/reference/settings.rst +++ b/docs/reference/settings.rst @@ -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`` diff --git a/sorl/thumbnail/conf/defaults.py b/sorl/thumbnail/conf/defaults.py index 5618622ed..ab6e30f9c 100644 --- a/sorl/thumbnail/conf/defaults.py +++ b/sorl/thumbnail/conf/defaults.py @@ -1,5 +1,3 @@ -from django.conf import settings - # When True ThumbnailNode.render can raise errors THUMBNAIL_DEBUG = False @@ -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 diff --git a/sorl/thumbnail/default.py b/sorl/thumbnail/default.py index fbbccc40e..d3092fe36 100644 --- a/sorl/thumbnail/default.py +++ b/sorl/thumbnail/default.py @@ -1,3 +1,4 @@ +from django.core.files.storage import storages from django.utils.functional import LazyObject from sorl.thumbnail.conf import settings @@ -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] backend = Backend() diff --git a/sorl/thumbnail/images.py b/sorl/thumbnail/images.py index a656ec2b9..a3bac713f 100644 --- a/sorl/thumbnail/images.py +++ b/sorl/thumbnail/images.py @@ -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