mirror of
https://github.com/cookiecutter/cookiecutter-django.git
synced 2025-01-24 00:04:13 +03:00
Replace custom static & media storage classes by passing options in the STORAGES
setting (#4803)
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.
This commit is contained in:
parent
4da8386f9c
commit
bda89eaa06
|
@ -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()
|
||||
|
|
|
@ -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 %}
|
||||
}
|
||||
|
|
|
@ -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 %}
|
Loading…
Reference in New Issue
Block a user