Skip to content

Commit

Permalink
fix #115 correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed May 22, 2024
1 parent 5a9bab6 commit eaca667
Showing 1 changed file with 12 additions and 19 deletions.
31 changes: 12 additions & 19 deletions import_export_celery/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@


def lazy_initialize_storage_class():
# If the user has specified a custom storage backend, use it.
if settings.STORAGES.get("IMPORT_EXPORT_CELERY_STORAGE"):
try:
# From Django 4.2 and later
from django.core.files.storage import storages
from django.core.files.storage.handler import InvalidStorageError
try:
storage_class = storages['IMPORT_EXPORT_CELERY_STORAGE']
except InvalidStorageError:
from django.utils.module_loading import import_string
storage_class = settings.DEFAULT_FILE_STORAGE
storage_class = import_string(storage_class)()
except ImportError:
# Deprecated since Django 4.2, Removed in Django 5.1
from django.core.files.storage import get_storage_class
storage_class = get_storage_class(
settings.STORAGES.get("IMPORT_EXPORT_CELERY_STORAGE")["BACKEND"]
)()
return storage_class
try:
# From Django 4.2 and later
from django.core.files.storage import storages
storage_alias = getattr(settings, "IMPORT_EXPORT_CELERY_STORAGE_ALIAS", "default")
storage_class = storages[storage_alias]
except ImportError:
# Deprecated since Django 4.2, Removed in Django 5.1
from django.core.files.storage import get_storage_class
old_storage = getattr(settings, "IMPORT_EXPORT_CELERY_STORAGE", settings.DEFAULT_FILE_STORAGE)
storage_class = get_storage_class(old_storage)()

return storage_class


class ImportExportFileField(models.FileField):
Expand Down

0 comments on commit eaca667

Please sign in to comment.