Skip to content

Commit a4475b7

Browse files
authored
fix: Django52 use STORAGES instead of DEFAULT_FILE_STORAGE and STATICFILES_STORAGE (#185)
Refactoring the code to replace the deprecated DEFAULT_FILE_STORAGE and STATICFILES_STORAGE settings with the more flexible and recommended STORAGES = {} pattern, a change that was recently done in various repos in community.
1 parent dda593b commit a4475b7

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

configuration_files/cms.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ DATABASES:
244244
DATA_DIR: /edx/var/edxapp
245245
DEFAULT_COURSE_VISIBILITY_IN_CATALOG: both
246246
DEFAULT_FEEDBACK_EMAIL: [email protected]
247-
DEFAULT_FILE_STORAGE: django.core.files.storage.FileSystemStorage
248247
DEFAULT_FROM_EMAIL: [email protected]
249248
DEFAULT_JWT_ISSUER:
250249
AUDIENCE: lms-key
@@ -494,6 +493,11 @@ SOCIAL_SHARING_SETTINGS:
494493
DASHBOARD_TWITTER: false
495494
STATIC_ROOT_BASE: /edx/var/edxapp/staticfiles
496495
STATIC_URL_BASE: /static/
496+
STORAGES:
497+
default:
498+
BACKEND: django.core.files.storage.FileSystemStorage
499+
staticfiles:
500+
BACKEND: django.contrib.staticfiles.storage.StaticFilesStorage
497501
STUDIO_NAME: Studio
498502
STUDIO_SHORT_NAME: Studio
499503
SUPPORT_SITE_LINK: ''

configuration_files/discovery.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ JWT_AUTH:
6969
JWT_PUBLIC_SIGNING_JWK_SET: ''
7070
LANGUAGE_CODE: en
7171
MEDIA_STORAGE_BACKEND:
72-
DEFAULT_FILE_STORAGE: django.core.files.storage.FileSystemStorage
72+
STORAGES:
73+
default:
74+
BACKEND: django.core.files.storage.FileSystemStorage
75+
staticfiles:
76+
BACKEND: django.contrib.staticfiles.storage.StaticFilesStorage
7377
MEDIA_ROOT: /edx/var/discovery/media
7478
MEDIA_URL: /media/
7579
OPENEXCHANGERATES_API_KEY: ''
@@ -91,7 +95,11 @@ SOCIAL_AUTH_EDX_OAUTH2_LOGOUT_URL: http://localhost:18000/logout
9195
SOCIAL_AUTH_EDX_OAUTH2_SECRET: discovery-sso-secret
9296
SOCIAL_AUTH_EDX_OAUTH2_URL_ROOT: http://127.0.0.1:8000
9397
SOCIAL_AUTH_REDIRECT_IS_HTTPS: false
94-
STATICFILES_STORAGE: django.contrib.staticfiles.storage.StaticFilesStorage
9598
STATIC_ROOT: /edx/var/discovery/staticfiles
99+
STORAGES:
100+
default:
101+
BACKEND: django.core.files.storage.FileSystemStorage
102+
staticfiles:
103+
BACKEND: django.contrib.staticfiles.storage.StaticFilesStorage
96104
TIME_ZONE: UTC
97105
USERNAME_REPLACEMENT_WORKER: OVERRIDE THIS WITH A VALID USERNAME

configuration_files/lms.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ DCS_SESSION_COOKIE_SAMESITE: Lax
265265
DCS_SESSION_COOKIE_SAMESITE_FORCE_ALL: true
266266
DEFAULT_COURSE_VISIBILITY_IN_CATALOG: both
267267
DEFAULT_FEEDBACK_EMAIL: [email protected]
268-
DEFAULT_FILE_STORAGE: django.core.files.storage.FileSystemStorage
269268
DEFAULT_FROM_EMAIL: [email protected]
270269
DEFAULT_JWT_ISSUER:
271270
AUDIENCE: lms-key
@@ -580,6 +579,11 @@ SOCIAL_SHARING_SETTINGS:
580579
DASHBOARD_TWITTER: false
581580
STATIC_ROOT_BASE: /edx/var/edxapp/staticfiles
582581
STATIC_URL_BASE: /static/
582+
STORAGES:
583+
default:
584+
BACKEND: django.core.files.storage.FileSystemStorage
585+
staticfiles:
586+
BACKEND: django.contrib.staticfiles.storage.StaticFilesStorage
583587
STUDIO_NAME: Studio
584588
STUDIO_SHORT_NAME: Studio
585589
SUPPORT_SITE_LINK: ''

py_configuration_files/credentials.py

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

45-
DEFAULT_FILE_STORAGE = os.environ.get("DEFAULT_FILE_STORAGE", "django.core.files.storage.FileSystemStorage")
45+
default_file_storage = os.environ.get("DEFAULT_FILE_STORAGE")
46+
47+
if default_file_storage:
48+
STORAGES["default"]["BACKEND"] = default_file_storage
49+
50+
staticfiles_storage = os.environ.get("STATICFILES_STORAGE")
51+
52+
if staticfiles_storage:
53+
STORAGES["staticfiles"]["BACKEND"] = staticfiles_storage
54+
4655
MEDIA_URL = os.environ.get("MEDIA_URL", "/media/")
4756

48-
STATICFILES_STORAGE = os.environ.get("STATICFILES_STORAGE", "django.contrib.staticfiles.storage.StaticFilesStorage")
4957
STATIC_URL = os.environ.get("STATIC_URL", "/static/")
5058

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

0 commit comments

Comments
 (0)