Fix handling of staticfile settings if cloud provider and whitenoise are selected (#5057)

Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
This commit is contained in:
Jens Kaeske 2024-05-13 22:45:55 +02:00 committed by GitHub
parent f82807f53a
commit 88a9a15dbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -118,7 +118,7 @@ AZURE_CONTAINER = env("DJANGO_AZURE_CONTAINER_NAME")
# STATIC & MEDIA
# ------------------------
STORAGES = {
{%- if cookiecutter.use_whitenoise == 'y' %}
{%- if cookiecutter.use_whitenoise == 'y' and cookiecutter.cloud_provider == 'None' %}
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
@ -133,6 +133,11 @@ STORAGES = {
"file_overwrite": False,
},
},
{%- if cookiecutter.use_whitenoise == 'y' %}
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
{%- else %}
"staticfiles": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
@ -140,6 +145,7 @@ STORAGES = {
"default_acl": "public-read",
},
},
{%- endif %}
{%- elif cookiecutter.cloud_provider == 'GCP' %}
"default": {
"BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
@ -148,6 +154,11 @@ STORAGES = {
"file_overwrite": False,
},
},
{%- if cookiecutter.use_whitenoise == 'y' %}
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
{%- else %}
"staticfiles": {
"BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
"OPTIONS": {
@ -155,6 +166,7 @@ STORAGES = {
"default_acl": "publicRead",
},
},
{%- endif %}
{%- elif cookiecutter.cloud_provider == 'Azure' %}
"default": {
"BACKEND": "storages.backends.azure_storage.AzureStorage",
@ -163,6 +175,11 @@ STORAGES = {
"file_overwrite": False,
},
},
{%- if cookiecutter.use_whitenoise == 'y' %}
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
{%- else %}
"staticfiles": {
"BACKEND": "storages.backends.azure_storage.AzureStorage",
"OPTIONS": {
@ -170,21 +187,28 @@ STORAGES = {
},
},
{%- endif %}
{%- endif %}
}
{%- endif %}
{%- if cookiecutter.cloud_provider == 'AWS' %}
MEDIA_URL = f"https://{aws_s3_domain}/media/"
{%- if cookiecutter.use_whitenoise == 'n' %}
COLLECTFAST_STRATEGY = "collectfast.strategies.boto3.Boto3Strategy"
STATIC_URL = f"https://{aws_s3_domain}/static/"
{%- endif %}
{%- elif cookiecutter.cloud_provider == 'GCP' %}
MEDIA_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/media/"
{%- if cookiecutter.use_whitenoise == 'n' %}
COLLECTFAST_STRATEGY = "collectfast.strategies.gcloud.GoogleCloudStrategy"
STATIC_URL = f"https://storage.googleapis.com/{GS_BUCKET_NAME}/static/"
{%- endif %}
{%- elif cookiecutter.cloud_provider == 'Azure' %}
MEDIA_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/media/"
{%- if cookiecutter.use_whitenoise == 'n' %}
STATIC_URL = f"https://{AZURE_ACCOUNT_NAME}.blob.core.windows.net/static/"
{%- endif %}
{%- endif %}
# EMAIL
# ------------------------------------------------------------------------------