Skip to content

Commit

Permalink
feat(update): added support for django 5 or bigger
Browse files Browse the repository at this point in the history
  • Loading branch information
niltonfrederico committed Aug 14, 2024
1 parent f3464df commit ffabe61
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion import_export_stomp/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.conf import settings
from django.core.files.storage import get_storage_class
from django.db import models
from import_export_stomp.utils import get_storage_class


class ImportExportFileField(models.FileField):
Expand Down
17 changes: 16 additions & 1 deletion import_export_stomp/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
from typing import Literal
from typing import Literal, Type
from typing import Union
from uuid import uuid4

from django import VERSION as DJANGO_VERSION
from django.conf import settings
from django.core.files.storage import Storage
from django_stomp.builder import build_publisher
from django_stomp.services.producer import auto_open_close_connection
from django_stomp.services.producer import do_inside_transaction
from import_export.formats.base_formats import DEFAULT_FORMATS
from django.utils.module_loading import import_string


USE_GET_STORAGE_CLASS = DJANGO_VERSION < (4, 2)
if USE_GET_STORAGE_CLASS:
from django.core.files.storage import get_storage_class as legacy_get_storage_class

IMPORT_EXPORT_STOMP_PROCESSING_QUEUE = getattr(
settings,
Expand All @@ -22,6 +30,13 @@
)


def get_storage_class(import_path: str = None) -> Type[Storage]:
if USE_GET_STORAGE_CLASS:
return legacy_get_storage_class(import_path)
else:
return import_string(import_path or settings.DEFAULT_FILE_STORAGE)


def get_formats():
return [
format
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.core.files.storage import get_storage_class
from import_export_stomp.utils import get_storage_class
from django.test import override_settings

from import_export_stomp.fields import ImportExportFileField
Expand Down

0 comments on commit ffabe61

Please sign in to comment.