From e41d6885c01ed2bd6d4cbcdecad0f6a8eaf16928 Mon Sep 17 00:00:00 2001 From: jkaeske Date: Wed, 24 Jan 2024 21:22:43 +0100 Subject: [PATCH] Remove custom, instantiated cloud storages module The custom cloud storages module has been deleted, and the settings have been updated to use the storage backend settings directly from each cloud provider's storage backend libraries. These changes have simplified the cloud storage configuration for each cloud provider in the production settings file. --- hooks/post_gen_project.py | 5 --- .../config/settings/production.py | 35 ++++++++++++++---- .../utils/__init__.py | 0 .../utils/storages.py | 36 ------------------- 4 files changed, 29 insertions(+), 47 deletions(-) delete mode 100644 {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/utils/__init__.py delete mode 100644 {{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/utils/storages.py diff --git a/hooks/post_gen_project.py b/hooks/post_gen_project.py index 37f96efc0..685bf90a7 100644 --- a/hooks/post_gen_project.py +++ b/hooks/post_gen_project.py @@ -429,10 +429,6 @@ def remove_drf_starter_files(): os.remove(os.path.join("{{cookiecutter.project_slug}}", "users", "tests", "test_swagger.py")) -def remove_storages_module(): - os.remove(os.path.join("{{cookiecutter.project_slug}}", "utils", "storages.py")) - - def main(): debug = "{{ cookiecutter.debug }}".lower() == "y" @@ -499,7 +495,6 @@ def main(): WARNING + "You chose to not use any cloud providers nor Docker, " "media files won't be served in production." + TERMINATOR ) - remove_storages_module() if "{{ cookiecutter.use_celery }}".lower() == "n": remove_celery_files() diff --git a/{{cookiecutter.project_slug}}/config/settings/production.py b/{{cookiecutter.project_slug}}/config/settings/production.py index 70dc6d7dd..7f6293571 100644 --- a/{{cookiecutter.project_slug}}/config/settings/production.py +++ b/{{cookiecutter.project_slug}}/config/settings/production.py @@ -115,24 +115,47 @@ STORAGES = { }, {%- elif cookiecutter.cloud_provider == 'AWS' %} "default": { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaS3Storage", + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "location": "media", + "file_overwrite": False, + }, }, "staticfiles": { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticS3Storage", + "BACKEND": "storages.backends.s3.S3Storage", + "OPTIONS": { + "location": "static", + "default_acl": "public-read", + }, }, {%- elif cookiecutter.cloud_provider == 'GCP' %} "default": { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaGoogleCloudStorage", + "BACKEND": "storages.backends.gcloud.GoogleCloudStorage", + "OPTIONS": { + "location": "media", + "file_overwrite": False, + }, }, "staticfiles": { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticGoogleCloudStorage", + "BACKEND": "storages.backends.gcloud.GoogleCloudStorage", + "OPTIONS": { + "location": "static", + "default_acl": "publicRead", + }, }, {%- elif cookiecutter.cloud_provider == 'Azure' %} "default": { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.MediaAzureStorage", + "BACKEND": "storages.backends.azure_storage.AzureStorage", + "OPTIONS": { + "location": "media", + "file_overwrite": False, + }, }, "staticfiles": { - "BACKEND": "{{cookiecutter.project_slug}}.utils.storages.StaticAzureStorage", + "BACKEND": "storages.backends.azure_storage.AzureStorage", + "OPTIONS": { + "location": "static", + }, }, {%- endif %} } diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/utils/__init__.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/utils/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/utils/storages.py b/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/utils/storages.py deleted file mode 100644 index cc055378a..000000000 --- a/{{cookiecutter.project_slug}}/{{cookiecutter.project_slug}}/utils/storages.py +++ /dev/null @@ -1,36 +0,0 @@ -{% if cookiecutter.cloud_provider == 'AWS' -%} -from storages.backends.s3 import S3Storage - - -class StaticS3Storage(S3Storage): - location = "static" - default_acl = "public-read" - - -class MediaS3Storage(S3Storage): - location = "media" - file_overwrite = False -{%- elif cookiecutter.cloud_provider == 'GCP' -%} -from storages.backends.gcloud import GoogleCloudStorage - - -class StaticGoogleCloudStorage(GoogleCloudStorage): - location = "static" - default_acl = "publicRead" - - -class MediaGoogleCloudStorage(GoogleCloudStorage): - location = "media" - file_overwrite = False -{%- elif cookiecutter.cloud_provider == 'Azure' -%} -from storages.backends.azure_storage import AzureStorage - - -class StaticAzureStorage(AzureStorage): - location = "static" - - -class MediaAzureStorage(AzureStorage): - location = "media" - file_overwrite = False -{%- endif %}