Skip to content

Commit

Permalink
Merge pull request #15 from juntossomosmais/feature/fix-breaking-chan…
Browse files Browse the repository at this point in the history
…ge-for-django

feat(update): added support for django 5 or bigger
  • Loading branch information
niltonfrederico authored Aug 14, 2024
2 parents f3464df + 1dcdf79 commit a30b296
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
exclude: migrations/

- repo: https://github.com/pycqa/autoflake
rev: v1.4
rev: v2.3.1
hooks:
- id: autoflake
args:
Expand Down
2 changes: 1 addition & 1 deletion example/winners/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ def test_get_export_job_mail_context(self):
expected_context = {
"app_label": "winners",
"model": "Winner",
"link": f"http://127.0.0.1:8000/adminimport_export_celery/exportjob/{export_job.id}/change/",
"link": f"http://127.0.0.1:8000/adminimport_export_celery/exportjob/{export_job.id}/change/", # noqa
}
self.assertEqual(context, expected_context)
3 changes: 2 additions & 1 deletion import_export_stomp/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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):
def __init__(self, *args, **kwargs):
Expand Down
15 changes: 15 additions & 0 deletions import_export_stomp/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from typing import Literal
from typing import 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.utils.module_loading import import_string
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

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,
"IMPORT_EXPORT_STOMP_PROCESSING_QUEUE",
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 pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "django-import-export-stomp"
version = "0.2.0"
version = "0.3.0"
description = "Run django-import-export processes using django-stomp"
authors = [
"Nilton Frederico Teixeira <9078708+niltonfrederico@users.noreply.github.com>",
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.conf import settings
from django.core.files.storage import get_storage_class
from django.test import override_settings

from import_export_stomp.fields import ImportExportFileField
from import_export_stomp.utils import get_storage_class


class TestFields:
Expand Down

0 comments on commit a30b296

Please sign in to comment.