Skip to content

Commit 53d1a60

Browse files
mubbsharanwarawais786feanil
authored
fix: Django52 use STORAGES instead of DEFAULT_FILE_STORAGE and STATICFILES_STORAGE (#2844)
* fix: Django52 use STORAGES instead of DEFAULT_FILE_STORAGE and STATICFILES_STORAGE Deprecate STATICFILES_STORAGE and DEFAULT_FILE_STORAGE, and use STORAGE in Django 5.2 * fix: address review comments --------- Co-authored-by: awais qureshi <[email protected]> Co-authored-by: Feanil Patel <[email protected]>
1 parent 9802798 commit 53d1a60

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

credentials/settings/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,14 @@
456456
FILE_STORAGE_BACKEND = {}
457457
EXTRA_APPS = []
458458
SESSION_EXPIRE_AT_BROWSER_CLOSE = False
459-
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
459+
STORAGES = {
460+
"default": {
461+
"BACKEND": "django.core.files.storage.FileSystemStorage",
462+
},
463+
"staticfiles": {
464+
"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage",
465+
},
466+
}
460467
CACHES = {
461468
"default": {
462469
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
@@ -474,7 +481,7 @@
474481
}
475482
API_ROOT = None
476483
MEDIA_STORAGE_BACKEND = {
477-
"DEFAULT_FILE_STORAGE": "django.core.files.storage.FileSystemStorage",
484+
"STORAGES": STORAGES,
478485
"MEDIA_ROOT": MEDIA_ROOT,
479486
"MEDIA_URL": MEDIA_URL,
480487
}

credentials/settings/devstack.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,17 @@
4343
EMAIL_BACKEND = "django.core.mail.backends.filebased.EmailBackend"
4444
EMAIL_FILE_PATH = "/tmp/credentials-emails"
4545

46-
DEFAULT_FILE_STORAGE = os.environ.get("DEFAULT_FILE_STORAGE", "django.core.files.storage.FileSystemStorage")
47-
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
46+
defaultfile_storage = os.environ.get("DEFAULT_FILE_STORAGE")
47+
48+
if defaultfile_storage:
49+
STORAGES["default"]["BACKEND"] = defaultfile_storage
50+
51+
staticfiles_storage = os.environ.get("STATICFILES_STORAGE")
4852

49-
STATICFILES_STORAGE = os.environ.get("STATICFILES_STORAGE", "django.contrib.staticfiles.storage.StaticFilesStorage")
53+
if staticfiles_storage:
54+
STORAGES["staticfiles"]["BACKEND"] = staticfiles_storage
55+
56+
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
5057
STATIC_URL = os.environ.get("STATIC_URL", "/static/")
5158

5259
# OAuth2 variables specific to social-auth/SSO login use case.

credentials/settings/production.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,20 @@
4444

4545
vars().update(config_from_yaml)
4646

47+
FILE_STORAGE_BACKEND = config_from_yaml.get("FILE_STORAGE_BACKEND", {})
48+
default_backend = FILE_STORAGE_BACKEND.pop("DEFAULT_FILE_STORAGE", None)
49+
static_backend = FILE_STORAGE_BACKEND.pop("STATICFILES_STORAGE", None)
50+
4751
# Load the files storage backend settings for django storages
52+
# In django==4.2.24 following line sets the DEFAULT_FILE_STORAGE and other AWS variables as per YAML.
4853
vars().update(FILE_STORAGE_BACKEND)
4954

55+
if default_backend:
56+
STORAGES["default"]["BACKEND"] = default_backend
57+
58+
if static_backend:
59+
STORAGES["staticfiles"]["BACKEND"] = static_backend
60+
5061
# make sure this happens after the configuration file overrides so format string can be overridden
5162
LOGGING = get_logger_config(format_string=LOGGING_FORMAT_STRING)
5263

credentials/settings/test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
# Local Directories
3737
TEST_ROOT = path("test_root")
38-
DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
38+
3939
MEDIA_ROOT = str(TEST_ROOT / "uploads")
4040
MEDIA_URL = "/static/uploads/"
4141

@@ -49,7 +49,6 @@
4949
"JWT_AUDIENCE": SOCIAL_AUTH_EDX_OAUTH2_KEY,
5050
}
5151
)
52-
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"
5352

5453
# Verifiable Credentials
5554
ENABLE_VERIFIABLE_CREDENTIALS = True

0 commit comments

Comments
 (0)