From 704cd5741b335245ec0d0e3dd3b0a0541fa46c31 Mon Sep 17 00:00:00 2001 From: Dimitar Todorov Date: Mon, 15 May 2023 13:43:00 +0300 Subject: [PATCH] improve_settings_and_fix_mypy_errors --- config/django/base.py | 7 ------- config/settings/files_and_storages.py | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/config/django/base.py b/config/django/base.py index 8d03232d..3e2bf64d 100644 --- a/config/django/base.py +++ b/config/django/base.py @@ -156,13 +156,6 @@ USE_TZ = True -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/3.0/howto/static-files/ - -STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") -STATIC_URL = "/static/" -STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage" - REST_FRAMEWORK = { "EXCEPTION_HANDLER": "styleguide_example.api.exception_handlers.drf_default_with_modifications_exception_handler", # 'EXCEPTION_HANDLER': 'styleguide_example.api.exception_handlers.hacksoft_proposed_exception_handler', diff --git a/config/settings/files_and_storages.py b/config/settings/files_and_storages.py index fd2ce2d1..3d090e1a 100644 --- a/config/settings/files_and_storages.py +++ b/config/settings/files_and_storages.py @@ -3,6 +3,19 @@ from config.env import BASE_DIR, env, env_to_enum from styleguide_example.files.enums import FileUploadStorage, FileUploadStrategy + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/3.0/howto/static-files/ +STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles") +STATIC_URL = "/static/" +STORAGES = { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "staticfiles": {"BACKEND": "whitenoise.storage.CompressedManifestStaticFilesStorage"}, +} + + FILE_UPLOAD_STRATEGY = env_to_enum(FileUploadStrategy, env("FILE_UPLOAD_STRATEGY", default="standard")) FILE_UPLOAD_STORAGE = env_to_enum(FileUploadStorage, env("FILE_UPLOAD_STORAGE", default="local")) @@ -16,7 +29,7 @@ if FILE_UPLOAD_STORAGE == FileUploadStorage.S3: # Using django-storages # https://django-storages.readthedocs.io/en/latest/backends/amazon-S3.html - DEFAULT_FILE_STORAGE = "storages.backends.s3boto3.S3Boto3Storage" + STORAGES["default"] = {"BACKEND": "storages.backends.s3boto3.S3Boto3Storage"} AWS_S3_ACCESS_KEY_ID = env("AWS_S3_ACCESS_KEY_ID") AWS_S3_SECRET_ACCESS_KEY = env("AWS_S3_SECRET_ACCESS_KEY")