From 27ae9c36e407559df2e2b892c5e20ee8df546007 Mon Sep 17 00:00:00 2001 From: Irfan Date: Sat, 1 Sep 2018 11:40:57 +0500 Subject: [PATCH 1/2] Fix #1771: Use full-fledge S3 Storage class in production settings sorl-thumbnail serialized and deserializes the storage class and during this process location parameter is lost if factory is used. Using a full-fledge storage class fixes this issue. See: https://stackoverflow.com/a/18046120/104731 --- CONTRIBUTORS.rst | 1 + .../config/settings/production.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index bbbfaf9a..b3a81e59 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -103,6 +103,7 @@ Listed in alphabetical order. Hendrik Schneider `@hendrikschneider`_ Henrique G. G. Pereira `@ikkebr`_ Ian Lee `@IanLee1521`_ + Irfan Ahmad `@erfaan`_ @erfaan Jan Van Bruggen `@jvanbrug`_ Jens Nilsson `@phiberjenz`_ Jimmy Gitonga `@afrowave`_ @afrowave diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 39df0cbf..606535d4 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -97,9 +97,19 @@ DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' MEDIA_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/' {%- else %} # region http://stackoverflow.com/questions/10390244/ +# Full-fledge class: https://stackoverflow.com/a/18046120/104731 from storages.backends.s3boto3 import S3Boto3Storage # noqa E402 -StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static') # noqa -MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media', file_overwrite=False) # noqa + + +class StaticRootS3BotoStorage(S3Boto3Storage): + location = 'static' + + +class MediaRootS3BotoStorage(S3Boto3Storage): + location = 'media' + file_overwrite = False + + # endregion DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage' MEDIA_URL = f'https://s3.amazonaws.com/{AWS_STORAGE_BUCKET_NAME}/media/' From 5427538dc74a5cbf1c49e62a241f8ed90a756a9b Mon Sep 17 00:00:00 2001 From: Irfan Date: Sat, 1 Sep 2018 11:55:31 +0500 Subject: [PATCH 2/2] Fix contributer github link --- CONTRIBUTORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index b3a81e59..2d9d278b 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -206,6 +206,7 @@ Listed in alphabetical order. .. _@durkode: https://github.com/durkode .. _@epileptic-fish: https://gihub.com/epileptic-fish .. _@eraldo: https://github.com/eraldo +.. _@erfaan: https://github.com/erfaan .. _@eriol: https://github.com/eriol .. _@eyadsibai: https://github.com/eyadsibai .. _@flyudvik: https://github.com/flyudvik