Skip to content

Commit 7cd09bf

Browse files
committed
chore: use Django 5.2 STORAGES
Depriciate STATICFILES_STORAGE and DEFAULT_FILE_STORAGE, and use STORAGE in Django 5.2
1 parent 8b65fac commit 7cd09bf

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

credentials/settings/base.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,10 @@
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": {"BACKEND": "django.core.files.storage.FileSystemStorage"},
461+
"staticfiles": {"BACKEND": "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"},
462+
}
460463
CACHES = {
461464
"default": {
462465
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
@@ -474,7 +477,9 @@
474477
}
475478
API_ROOT = None
476479
MEDIA_STORAGE_BACKEND = {
477-
"DEFAULT_FILE_STORAGE": "django.core.files.storage.FileSystemStorage",
480+
"STORAGES": {
481+
"default": {"BACKEND": STORAGES["default"]["BACKEND"]},
482+
},
478483
"MEDIA_ROOT": MEDIA_ROOT,
479484
"MEDIA_URL": MEDIA_URL,
480485
}

credentials/settings/devstack.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
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")
46+
STORAGES["default"]["BACKEND"] = os.environ.get(
47+
STORAGES["default"]["BACKEND"], "django.core.files.storage.FileSystemStorage"
48+
)
4749
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
4850

49-
STATICFILES_STORAGE = os.environ.get("STATICFILES_STORAGE", "django.contrib.staticfiles.storage.StaticFilesStorage")
51+
STORAGES["staticfiles"]["BACKEND"] = "django.contrib.staticfiles.storage.StaticFilesStorage"
5052
STATIC_URL = os.environ.get("STATIC_URL", "/static/")
5153

5254
# 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
@@ -42,8 +42,19 @@
4242
if value:
4343
vars()[key].update(value)
4444

45+
if "DEFAULT_FILE_STORAGE" in config_from_yaml and "default" not in STORAGES:
46+
STORAGES["default"] = {"BACKEND": config_from_yaml.pop("DEFAULT_FILE_STORAGE")}
47+
vars().update(STORAGES)
48+
49+
if "STATICFILES_STORAGE" in config_from_yaml and "staticfiles" not in STORAGES:
50+
STORAGES["staticfiles"] = {"BACKEND": config_from_yaml.pop("STATICFILES_STORAGE")}
51+
vars().update(STORAGES)
52+
4553
vars().update(config_from_yaml)
4654

55+
if "DEFAULT_FILE_STORAGE" in FILE_STORAGE_BACKEND:
56+
MEDIA_STORAGE_BACKEND["STORAGES"] = {"default": {"BACKEND": MEDIA_STORAGE_BACKEND.pop("DEFAULT_FILE_STORAGE")}}
57+
4758
# Load the files storage backend settings for django storages
4859
vars().update(FILE_STORAGE_BACKEND)
4960

credentials/settings/test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535

3636
# Local Directories
3737
TEST_ROOT = path("test_root")
38-
DEFAULT_FILE_STORAGE = "django.core.files.storage.FileSystemStorage"
38+
STORAGES["default"]["BACKEND"] = os.environ.get(
39+
STORAGES["default"]["BACKEND"], "django.core.files.storage.FileSystemStorage"
40+
)
3941
MEDIA_ROOT = str(TEST_ROOT / "uploads")
4042
MEDIA_URL = "/static/uploads/"
4143

@@ -49,7 +51,7 @@
4951
"JWT_AUDIENCE": SOCIAL_AUTH_EDX_OAUTH2_KEY,
5052
}
5153
)
52-
STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"
54+
STORAGES["staticfiles"]["BACKEND"] = "django.contrib.staticfiles.storage.StaticFilesStorage"
5355

5456
# Verifiable Credentials
5557
ENABLE_VERIFIABLE_CREDENTIALS = True

0 commit comments

Comments
 (0)