diff --git a/.circleci/config.yml b/.circleci/config.yml index 8a21044..31919e2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,37 +4,37 @@ py38default: &py38default docker: - image: circleci/python:3.8 steps: - - setup_remote_docker: - docker_layer_caching: false - - checkout - - attach_workspace: - at: /tmp/images - - run: docker load -i /tmp/images/py38.tar || true - - run: docker run py38 tox -e $CIRCLE_JOB + - setup_remote_docker: + docker_layer_caching: false + - checkout + - attach_workspace: + at: /tmp/images + - run: docker load -i /tmp/images/py38.tar || true + - run: docker run py38 tox -e $CIRCLE_JOB py39default: &py39default docker: - image: circleci/python:3.9 steps: - - setup_remote_docker: - docker_layer_caching: false - - checkout - - attach_workspace: - at: /tmp/images - - run: docker load -i /tmp/images/py39.tar || true - - run: docker run py39 tox -e $CIRCLE_JOB + - setup_remote_docker: + docker_layer_caching: false + - checkout + - attach_workspace: + at: /tmp/images + - run: docker load -i /tmp/images/py39.tar || true + - run: docker run py39 tox -e $CIRCLE_JOB py310default: &py310default docker: - image: circleci/python:3.10 steps: - - setup_remote_docker: - docker_layer_caching: false - - checkout - - attach_workspace: - at: /tmp/images - - run: docker load -i /tmp/images/py310.tar || true - - run: docker run py310 tox -e $CIRCLE_JOB + - setup_remote_docker: + docker_layer_caching: false + - checkout + - attach_workspace: + at: /tmp/images + - run: docker load -i /tmp/images/py310.tar || true + - run: docker run py310 tox -e $CIRCLE_JOB py38_requires: &py38_requires requires: @@ -60,8 +60,8 @@ jobs: - run: mkdir images - run: docker save -o images/py38.tar py38 - persist_to_workspace: - root: images - paths: py38.tar + root: images + paths: py38.tar py39_base: docker: - image: circleci/python:3.9 @@ -73,8 +73,8 @@ jobs: - run: mkdir images - run: docker save -o images/py39.tar py39 - persist_to_workspace: - root: images - paths: py39.tar + root: images + paths: py39.tar py310_base: docker: - image: circleci/python:3.10 @@ -86,8 +86,8 @@ jobs: - run: mkdir images - run: docker save -o images/py310.tar py310 - persist_to_workspace: - root: images - paths: py310.tar + root: images + paths: py310.tar flake8: <<: *py310default @@ -103,6 +103,8 @@ jobs: <<: *py39default py310-dj42-sqlite-cms40: <<: *py310default + py310-dj42-sqlite-cms41: + <<: *py310default ####################### @@ -133,3 +135,6 @@ workflows: - py310-dj42-sqlite-cms40: requires: - py310_base + - py310-dj42-sqlite-cms41: + requires: + - py310_base diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3a442d2..aaaaba1 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,8 @@ Changelog Unreleased ========== +* Django CMS 4.1 support added + 1.5.0 (2024-05-16) ================== diff --git a/djangocms_references/compat.py b/djangocms_references/compat.py index bef3dce..f5d98c8 100644 --- a/djangocms_references/compat.py +++ b/djangocms_references/compat.py @@ -1,3 +1,12 @@ +from cms import __version__ as cms_version + + +try: + from packaging.version import Version +except ModuleNotFoundError: + from distutils.version import LooseVersion as Version + + def is_versioning_installed(): try: import djangocms_versioning # noqa: F401 @@ -7,4 +16,7 @@ def is_versioning_installed(): return True +DJANGO_CMS_4_1 = Version(cms_version) >= Version('4.1') + + VERSIONING_INSTALLED = is_versioning_installed() diff --git a/djangocms_references/monkeypatch/admin.py b/djangocms_references/monkeypatch/admin.py index b0af466..0697b81 100644 --- a/djangocms_references/monkeypatch/admin.py +++ b/djangocms_references/monkeypatch/admin.py @@ -4,6 +4,7 @@ from djangocms_alias import admin as AliasOriginalAdmin from djangocms_snippet import admin as SnippetOriginalAdmin +from djangocms_references.compat import DJANGO_CMS_4_1 def generate_get_references_link(content_grouper): @@ -35,12 +36,16 @@ def inner(self, *args, **kwargs): return inner -AliasOriginalAdmin.AliasContentAdmin._get_references_link = generate_get_references_link('alias') -AliasOriginalAdmin.AliasContentAdmin.get_list_actions = get_list_actions( - AliasOriginalAdmin.AliasContentAdmin.get_list_actions -) +if not DJANGO_CMS_4_1: + AliasOriginalAdmin.AliasContentAdmin._get_references_link = generate_get_references_link('alias') + AliasOriginalAdmin.AliasContentAdmin.get_list_actions = get_list_actions( + AliasOriginalAdmin.AliasContentAdmin.get_list_actions + ) -SnippetOriginalAdmin.SnippetAdmin._get_references_link = generate_get_references_link('snippet_grouper') -SnippetOriginalAdmin.SnippetAdmin.get_list_actions = get_list_actions( - SnippetOriginalAdmin.SnippetAdmin.get_list_actions -) + SnippetOriginalAdmin.SnippetAdmin._get_references_link = generate_get_references_link('snippet_grouper') + SnippetOriginalAdmin.SnippetAdmin.get_list_actions = get_list_actions( + SnippetOriginalAdmin.SnippetAdmin.get_list_actions + ) +else: + # TODO: add reference button for django cms 4.1 + pass diff --git a/tests/requirements/dj42_cms41.txt b/tests/requirements/dj42_cms41.txt new file mode 100644 index 0000000..73b9c6d --- /dev/null +++ b/tests/requirements/dj42_cms41.txt @@ -0,0 +1,13 @@ +coverage +django-app-helper +factory-boy +flake8 +isort +tox + + +Django>=4.2,<5.0 +django-cms>=4.1.0 +djangocms-versioning==2.0.2 +https://github.com/django-cms/djangocms-snippet/tarball/master#egg=djangocms-snippet==5.0.0.a1 +https://github.com/django-cms/djangocms-alias/tarball/master#egg=djangocms-alias \ No newline at end of file diff --git a/tests/test_admin.py b/tests/test_admin.py index fa0bf5e..04d69dd 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -1,3 +1,5 @@ +from unittest import skipIf + from django.contrib import admin from django.contrib.contenttypes.models import ContentType from django.urls import reverse_lazy @@ -9,9 +11,14 @@ from djangocms_snippet.admin import SnippetAdmin as SnippetContentAdmin from djangocms_snippet.models import Snippet as SnippetContent, SnippetGrouper from djangocms_versioning.models import Version +from djangocms_references.compat import DJANGO_CMS_4_1 class AliasAdminReferencesMonkeyPatchTestCase(CMSTestCase): + @skipIf( + DJANGO_CMS_4_1, + "AliasContentAdmin doesn't derive from `ExtendedVersionAdminMixin`, so no `get_list_display` exist", + ) def test_list_display(self): """ The monkeypatch extends the alias admin, adding the show references link @@ -42,6 +49,10 @@ def test_list_display(self): class SnippetAdminReferencesMonkeyPatchTestCase(CMSTestCase): + @skipIf( + DJANGO_CMS_4_1, + "AliasContentAdmin doesn't derive from `ExtendedVersionAdminMixin`, so no `get_list_display` exist", + ) def test_list_display(self): """ The monkeypatch extends the snippet admin, adding the show references link diff --git a/tox.ini b/tox.ini index 60fcca8..9ca38d6 100644 --- a/tox.ini +++ b/tox.ini @@ -11,8 +11,9 @@ deps = flake8: -r{toxinidir}/tests/requirements/requirements_base.txt isort: -r{toxinidir}/tests/requirements/requirements_base.txt - dj32: -r{toxinidir}/tests/requirements/dj32_cms40.txt - dj42: -r{toxinidir}/tests/requirements/dj42_cms40.txt + dj32_cms40: -r{toxinidir}/tests/requirements/dj32_cms40.txt + dj42_cms40: -r{toxinidir}/tests/requirements/dj42_cms40.txt + dj42_cms41: -r{toxinidir}/tests/requirements/dj42_cms41.txt basepython = py38: python3.8