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