Skip to content

Commit 03e8c83

Browse files
committed
fix: fixing code.
1 parent 05bd1d3 commit 03e8c83

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

openedx/core/djangoapps/user_api/accounts/image_helpers.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55

66
import hashlib
77

8+
from django import VERSION
89
from django.conf import settings
910
from django.contrib.staticfiles.storage import staticfiles_storage
11+
from django.core.files.storage import storages
1012
from django.core.exceptions import ObjectDoesNotExist
1113
from django.utils.module_loading import import_string
1214

@@ -33,11 +35,22 @@ def get_profile_image_storage():
3335
An instance of the configured storage backend.
3436
"""
3537
config = getattr(settings, 'PROFILE_IMAGE_BACKEND', {})
36-
storage_class_path = config.get('class') or getattr(
37-
settings, 'DEFAULT_FILE_STORAGE', 'django.core.files.storage.FileSystemStorage'
38-
)
38+
storage_class_path = config.get('class')
39+
options = config.get('options', {})
40+
41+
if not storage_class_path:
42+
# Django 5.x STORAGES fallback
43+
if django_version[0] >= 5 and hasattr(settings, 'STORAGES') and 'default' in settings.STORAGES:
44+
return storages['default']
45+
else:
46+
# Legacy fallback
47+
storage_class_path = getattr(
48+
settings, 'DEFAULT_FILE_STORAGE',
49+
'django.core.files.storage.FileSystemStorage'
50+
)
51+
3952
storage_class = import_string(storage_class_path)
40-
return storage_class(**config.get('options', {}))
53+
return storage_class(**options)
4154

4255

4356
def _make_profile_image_name(username):

0 commit comments

Comments
 (0)