Skip to content

Commit

Permalink
fix: django storages
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Feb 7, 2025
1 parent 75aca37 commit 12c527e
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 47 deletions.
32 changes: 25 additions & 7 deletions codeforlife/settings/django.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,29 @@ def get_databases():
},
]

# File storage
# https://docs.djangoproject.com/en/4.2/topics/files/#file-storage
# Storages
# https://docs.djangoproject.com/en/4.2/ref/settings/#storages

DEFAULT_FILE_STORAGE = (
"django.core.files.storage.FileSystemStorage"
if ENV == "local"
else "storages.backends.s3.S3Storage"
)
STORAGES: t.Dict[str, t.Any] = {
"default": (
{
"BACKEND": "django.core.files.storage.FileSystemStorage",
}
if ENV == "local"
else {
"BACKEND": "storages.backends.s3.S3Storage",
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings
"OPTIONS": {
"bucket_name": os.getenv("S3_STORAGE_BUCKET_NAME"),
"default_acl": os.getenv("S3_STORAGE_DEFAULT_ACL"),
"location": os.getenv("S3_STORAGE_LOCATION"),
"region_name": os.getenv("S3_STORAGE_REGION_NAME"),
"custom_domain": os.getenv("S3_STORAGE_CUSTOM_DOMAIN"),
"addressing_style": os.getenv("S3_STORAGE_ADDRESSING_STYLE"),
},
}
),
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}
80 changes: 40 additions & 40 deletions codeforlife/settings/third_party.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
This file contains custom settings defined by third party extensions.
"""

import json
import os
# import json
# import os

from .custom import SERVICE_SITE_URL
from .django import ENV
Expand Down Expand Up @@ -31,41 +31,41 @@
# Django storages
# https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html#settings

AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
AWS_S3_OBJECT_PARAMETERS = json.loads(
os.getenv("AWS_S3_OBJECT_PARAMETERS", "{}")
)
AWS_DEFAULT_ACL = os.getenv("AWS_DEFAULT_ACL")
AWS_QUERYSTRING_AUTH = bool(int(os.getenv("AWS_QUERYSTRING_AUTH", "1")))
AWS_S3_MAX_MEMORY_SIZE = int(os.getenv("AWS_S3_MAX_MEMORY_SIZE", "0"))
AWS_QUERYSTRING_EXPIRE = int(os.getenv("AWS_QUERYSTRING_EXPIRE", "3600"))
AWS_S3_URL_PROTOCOL = os.getenv("AWS_S3_URL_PROTOCOL", "https:")
AWS_S3_FILE_OVERWRITE = bool(int(os.getenv("AWS_S3_FILE_OVERWRITE", "1")))
AWS_LOCATION = os.getenv("AWS_LOCATION", "")
AWS_IS_GZIPPED = bool(int(os.getenv("AWS_IS_GZIPPED", "0")))
GZIP_CONTENT_TYPES = os.getenv(
"GZIP_CONTENT_TYPES",
"("
+ ",".join(
[
"text/css",
"text/javascript",
"application/javascript",
"application/x-javascript",
"image/svg+xml",
]
)
+ ")",
)
AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME")
AWS_S3_USE_SSL = bool(int(os.getenv("AWS_S3_USE_SSL", "1")))
AWS_S3_VERIFY = os.getenv("AWS_S3_VERIFY")
AWS_S3_ENDPOINT_URL = os.getenv("AWS_S3_ENDPOINT_URL")
AWS_S3_ADDRESSING_STYLE = os.getenv("AWS_S3_ADDRESSING_STYLE")
AWS_S3_PROXIES = os.getenv("AWS_S3_PROXIES")
AWS_S3_TRANSFER_CONFIG = os.getenv("AWS_S3_TRANSFER_CONFIG")
AWS_S3_CUSTOM_DOMAIN = os.getenv("AWS_S3_CUSTOM_DOMAIN")
AWS_CLOUDFRONT_KEY = os.getenv("AWS_CLOUDFRONT_KEY")
AWS_CLOUDFRONT_KEY_ID = os.getenv("AWS_CLOUDFRONT_KEY_ID")
AWS_S3_SIGNATURE_VERSION = os.getenv("AWS_S3_SIGNATURE_VERSION")
AWS_S3_CLIENT_CONFIG = os.getenv("AWS_S3_CLIENT_CONFIG")
# AWS_STORAGE_BUCKET_NAME = os.getenv("AWS_STORAGE_BUCKET_NAME")
# AWS_S3_OBJECT_PARAMETERS = json.loads(
# os.getenv("AWS_S3_OBJECT_PARAMETERS", "{}")
# )
# AWS_DEFAULT_ACL = os.getenv("AWS_DEFAULT_ACL")
# AWS_QUERYSTRING_AUTH = bool(int(os.getenv("AWS_QUERYSTRING_AUTH", "1")))
# AWS_S3_MAX_MEMORY_SIZE = int(os.getenv("AWS_S3_MAX_MEMORY_SIZE", "0"))
# AWS_QUERYSTRING_EXPIRE = int(os.getenv("AWS_QUERYSTRING_EXPIRE", "3600"))
# AWS_S3_URL_PROTOCOL = os.getenv("AWS_S3_URL_PROTOCOL", "https:")
# AWS_S3_FILE_OVERWRITE = bool(int(os.getenv("AWS_S3_FILE_OVERWRITE", "1")))
# AWS_LOCATION = os.getenv("AWS_LOCATION", "")
# AWS_IS_GZIPPED = bool(int(os.getenv("AWS_IS_GZIPPED", "0")))
# GZIP_CONTENT_TYPES = os.getenv(
# "GZIP_CONTENT_TYPES",
# "("
# + ",".join(
# [
# "text/css",
# "text/javascript",
# "application/javascript",
# "application/x-javascript",
# "image/svg+xml",
# ]
# )
# + ")",
# )
# AWS_S3_REGION_NAME = os.getenv("AWS_S3_REGION_NAME")
# AWS_S3_USE_SSL = bool(int(os.getenv("AWS_S3_USE_SSL", "1")))
# AWS_S3_VERIFY = os.getenv("AWS_S3_VERIFY")
# AWS_S3_ENDPOINT_URL = os.getenv("AWS_S3_ENDPOINT_URL")
# AWS_S3_ADDRESSING_STYLE = os.getenv("AWS_S3_ADDRESSING_STYLE")
# AWS_S3_PROXIES = os.getenv("AWS_S3_PROXIES")
# AWS_S3_TRANSFER_CONFIG = os.getenv("AWS_S3_TRANSFER_CONFIG")
# AWS_S3_CUSTOM_DOMAIN = os.getenv("AWS_S3_CUSTOM_DOMAIN")
# AWS_CLOUDFRONT_KEY = os.getenv("AWS_CLOUDFRONT_KEY")
# AWS_CLOUDFRONT_KEY_ID = os.getenv("AWS_CLOUDFRONT_KEY_ID")
# AWS_S3_SIGNATURE_VERSION = os.getenv("AWS_S3_SIGNATURE_VERSION")
# AWS_S3_CLIENT_CONFIG = os.getenv("AWS_S3_CLIENT_CONFIG")

0 comments on commit 12c527e

Please sign in to comment.