From 90174324210e778f143e877b16a30fbc06789f4e Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Tue, 1 Aug 2017 22:34:09 +0100 Subject: [PATCH 1/4] Update django-storages fixes #998 The -redux project is now the official project, update to the latest version --- {{cookiecutter.project_slug}}/requirements/production.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index bdb9da9a..743ee629 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -17,7 +17,7 @@ gunicorn==19.7.1 # Static and Media Storage # ------------------------------------------------ boto==2.48.0 -django-storages-redux==1.3.3 +django-storages==1.6.5 {% if cookiecutter.use_whitenoise != 'y' -%} Collectfast==0.5.2 {%- endif %} From 4e9f18b52dbdd1aaaf277d42f43c1d97be593f79 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 2 Aug 2017 00:51:31 +0100 Subject: [PATCH 2/4] Add @browniebroke to CONTRIBUTORS.rst --- CONTRIBUTORS.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index 60a29975..f57280e5 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -63,7 +63,8 @@ Listed in alphabetical order. Bo Lopker `@blopker`_ Bouke Haarsma Brent Payne `@brentpayne`_ @brentpayne - Burhan Khalid `@burhan`_ @burhan + Bruno Alla               `@browniebroke`_ @_BrunoAlla + Burhan Khalid            `@burhan`_                   @burhan Catherine Devlin `@catherinedevlin`_ Cédric Gaspoz `@cgaspoz`_ Chris Curvey `@ccurvey`_ @@ -165,6 +166,7 @@ Listed in alphabetical order. .. _@bloodpet: https://github.com/bloodpet .. _@blopker: https://github.com/blopker .. _@bogdal: https://github.com/bogdal +.. _@browniebroke: https://github.com/browniebroke .. _@burhan: https://github.com/burhan .. _@c-rhodes: https://github.com/c-rhodes .. _@caffodian: https://github.com/caffodian From 12db5176d6c4c3ba531f0ad3c47f16b543698322 Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 2 Aug 2017 20:00:03 +0100 Subject: [PATCH 3/4] Upgrade to boto3 fixes #998 - Boto3 is the replacement of boto, switch to the latest version - Switch django-storages class to the one based on Boto3 - AWS_S3_CALLING_FORMAT isn't relevant anymore --- .../config/settings/production.py | 10 ++++------ .../requirements/production.txt | 2 +- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index ca79c163..01c245fa 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -12,7 +12,6 @@ Production Configurations {% endif %} """ -from boto.s3.connection import OrdinaryCallingFormat {% if cookiecutter.use_sentry_for_error_reporting == 'y' %} import logging {% endif %} @@ -98,7 +97,6 @@ AWS_SECRET_ACCESS_KEY = env('DJANGO_AWS_SECRET_ACCESS_KEY') AWS_STORAGE_BUCKET_NAME = env('DJANGO_AWS_STORAGE_BUCKET_NAME') AWS_AUTO_CREATE_BUCKET = True AWS_QUERYSTRING_AUTH = False -AWS_S3_CALLING_FORMAT = OrdinaryCallingFormat() # AWS cache settings, don't change unless you know what you're doing: AWS_EXPIRY = 60 * 60 * 24 * 7 @@ -117,9 +115,9 @@ AWS_HEADERS = { MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME {% else %} # See:http://stackoverflow.com/questions/10390244/ -from storages.backends.s3boto import S3BotoStorage -StaticRootS3BotoStorage = lambda: S3BotoStorage(location='static') -MediaRootS3BotoStorage = lambda: S3BotoStorage(location='media') +from storages.backends.s3boto3 import S3Boto3Storage +StaticRootS3BotoStorage = lambda: S3Boto3Storage(location='static') +MediaRootS3BotoStorage = lambda: S3Boto3Storage(location='media') DEFAULT_FILE_STORAGE = 'config.settings.production.MediaRootS3BotoStorage' MEDIA_URL = 'https://s3.amazonaws.com/%s/media/' % AWS_STORAGE_BUCKET_NAME @@ -141,7 +139,7 @@ INSTALLED_APPS = ['collectfast', ] + INSTALLED_APPS {% if cookiecutter.use_compressor == 'y'-%} # COMPRESSOR # ------------------------------------------------------------------------------ -COMPRESS_STORAGE = 'storages.backends.s3boto.S3BotoStorage' +COMPRESS_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' COMPRESS_URL = STATIC_URL COMPRESS_ENABLED = env.bool('COMPRESS_ENABLED', default=True) {%- endif %} diff --git a/{{cookiecutter.project_slug}}/requirements/production.txt b/{{cookiecutter.project_slug}}/requirements/production.txt index 743ee629..4f345b4d 100644 --- a/{{cookiecutter.project_slug}}/requirements/production.txt +++ b/{{cookiecutter.project_slug}}/requirements/production.txt @@ -16,7 +16,7 @@ gunicorn==19.7.1 # Static and Media Storage # ------------------------------------------------ -boto==2.48.0 +boto3==1.4.5 django-storages==1.6.5 {% if cookiecutter.use_whitenoise != 'y' -%} Collectfast==0.5.2 From 4be48b799985185d7c389a09980d5057270db70a Mon Sep 17 00:00:00 2001 From: Bruno Alla Date: Wed, 2 Aug 2017 20:10:49 +0100 Subject: [PATCH 4/4] Use django-storages for media files if using WhiteNoise - fixes #1192 As per the discussion in #869, WhiteNoise is for serving static files not for media files (files uploaded from the app by users). For such thing, we still need `DEFAULT_FILE_STORAGE` to be set and we use django-storages for that. --- {{cookiecutter.project_slug}}/config/settings/production.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 01c245fa..98949ca0 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -1,7 +1,9 @@ """ Production Configurations -- Use Amazon's S3 for storing static files and uploaded media +{% if cookiecutter.use_whitenoise == 'y' -%} +- Use WhiteNoise for serving static files{% endif %} +- Use Amazon's S3 for {% if cookiecutter.use_whitenoise == 'n' -%}storing static files {% endif %}and uploaded media - Use mailgun to send emails - Use Redis for cache {% if cookiecutter.use_sentry_for_error_reporting == 'y' %} @@ -113,6 +115,7 @@ AWS_HEADERS = { # stored files. {% if cookiecutter.use_whitenoise == 'y' -%} MEDIA_URL = 'https://s3.amazonaws.com/%s/' % AWS_STORAGE_BUCKET_NAME +DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' {% else %} # See:http://stackoverflow.com/questions/10390244/ from storages.backends.s3boto3 import S3Boto3Storage