Skip to content

Commit

Permalink
Fix handling of staticfile settings if cloud provider and whitenoise …
Browse files Browse the repository at this point in the history
…are selected (#5057)

Co-authored-by: Bruno Alla <alla.brunoo@gmail.com>
  • Loading branch information
jkaeske and browniebroke committed May 13, 2024
1 parent f82807f commit 88a9a15
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion {{cookiecutter.project_slug}}/config/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
# 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",
},
Expand All @@ -133,13 +133,19 @@
"file_overwrite": False,
},
},
{%- if cookiecutter.use_whitenoise == 'y' %}
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
{%- else %}
"staticfiles": {
"BACKEND": "storages.backends.s3.S3Storage",
"OPTIONS": {
"location": "static",
"default_acl": "public-read",
},
},
{%- endif %}
{%- elif cookiecutter.cloud_provider == 'GCP' %}
"default": {
"BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
Expand All @@ -148,13 +154,19 @@
"file_overwrite": False,
},
},
{%- if cookiecutter.use_whitenoise == 'y' %}
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
{%- else %}
"staticfiles": {
"BACKEND": "storages.backends.gcloud.GoogleCloudStorage",
"OPTIONS": {
"location": "static",
"default_acl": "publicRead",
},
},
{%- endif %}
{%- elif cookiecutter.cloud_provider == 'Azure' %}
"default": {
"BACKEND": "storages.backends.azure_storage.AzureStorage",
Expand All @@ -163,28 +175,40 @@
"file_overwrite": False,
},
},
{%- if cookiecutter.use_whitenoise == 'y' %}
"staticfiles": {
"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage",
},
{%- else %}
"staticfiles": {
"BACKEND": "storages.backends.azure_storage.AzureStorage",
"OPTIONS": {
"location": "static",
},
},
{%- 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
# ------------------------------------------------------------------------------
Expand Down

0 comments on commit 88a9a15

Please sign in to comment.