diff --git a/credentials/settings/base.py b/credentials/settings/base.py index d95f88cad..f2ecf8b50 100644 --- a/credentials/settings/base.py +++ b/credentials/settings/base.py @@ -456,7 +456,14 @@ FILE_STORAGE_BACKEND = {} EXTRA_APPS = [] SESSION_EXPIRE_AT_BROWSER_CLOSE = False -STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage" +STORAGES = { + "default": { + "BACKEND": "django.core.files.storage.FileSystemStorage", + }, + "staticfiles": { + "BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage", + }, +} CACHES = { "default": { "BACKEND": "django.core.cache.backends.locmem.LocMemCache", @@ -474,7 +481,7 @@ } API_ROOT = None MEDIA_STORAGE_BACKEND = { - "DEFAULT_FILE_STORAGE": "django.core.files.storage.FileSystemStorage", + "STORAGES": STORAGES, "MEDIA_ROOT": MEDIA_ROOT, "MEDIA_URL": MEDIA_URL, } diff --git a/credentials/settings/devstack.py b/credentials/settings/devstack.py index a36b5939e..f9da5e589 100644 --- a/credentials/settings/devstack.py +++ b/credentials/settings/devstack.py @@ -43,10 +43,17 @@ EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend" EMAIL_FILE_PATH = "/tmp/credentials-emails" -DEFAULT_FILE_STORAGE = os.environ.get("DEFAULT_FILE_STORAGE", "django.core.files.storage.FileSystemStorage") -MEDIA_URL = os.environ.get("MEDIA_URL", "/media/") +defaultfile_storage = os.environ.get("DEFAULT_FILE_STORAGE") + +if defaultfile_storage: + STORAGES["default"]["BACKEND"] = defaultfile_storage + +staticfiles_storage = os.environ.get("STATICFILES_STORAGE") -STATICFILES_STORAGE = os.environ.get("STATICFILES_STORAGE", "django.contrib.staticfiles.storage.StaticFilesStorage") +if staticfiles_storage: + STORAGES["staticfiles"]["BACKEND"] = staticfiles_storage + +MEDIA_URL = os.environ.get("MEDIA_URL", "/media/") STATIC_URL = os.environ.get("STATIC_URL", "/static/") # OAuth2 variables specific to social-auth/SSO login use case. diff --git a/credentials/settings/production.py b/credentials/settings/production.py index 8b3ad8828..0cd258d99 100644 --- a/credentials/settings/production.py +++ b/credentials/settings/production.py @@ -44,9 +44,20 @@ vars().update(config_from_yaml) + FILE_STORAGE_BACKEND = config_from_yaml.get("FILE_STORAGE_BACKEND", {}) + default_backend = FILE_STORAGE_BACKEND.pop("DEFAULT_FILE_STORAGE", None) + static_backend = FILE_STORAGE_BACKEND.pop("STATICFILES_STORAGE", None) + # Load the files storage backend settings for django storages + # In django==4.2.24 following line sets the DEFAULT_FILE_STORAGE and other AWS variables as per YAML. vars().update(FILE_STORAGE_BACKEND) + if default_backend: + STORAGES["default"]["BACKEND"] = default_backend + + if static_backend: + STORAGES["staticfiles"]["BACKEND"] = static_backend + # make sure this happens after the configuration file overrides so format string can be overridden LOGGING = get_logger_config(format_string=LOGGING_FORMAT_STRING) diff --git a/credentials/settings/test.py b/credentials/settings/test.py index a522fc77b..153917228 100644 --- a/credentials/settings/test.py +++ b/credentials/settings/test.py @@ -35,7 +35,7 @@ # Local Directories TEST_ROOT = path("test_root") -DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage" + MEDIA_ROOT = str(TEST_ROOT / "uploads") MEDIA_URL = "/static/uploads/" @@ -49,7 +49,6 @@ "JWT_AUDIENCE": SOCIAL_AUTH_EDX_OAUTH2_KEY, } ) -STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage" # Verifiable Credentials ENABLE_VERIFIABLE_CREDENTIALS = True