Skip to content

Commit

Permalink
feat: add django cms 4.1 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh Yu committed Aug 21, 2024
1 parent 93d6940 commit 820ab37
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 37 deletions.
59 changes: 32 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -103,6 +103,8 @@ jobs:
<<: *py39default
py310-dj42-sqlite-cms40:
<<: *py310default
py310-dj42-sqlite-cms41:
<<: *py310default

#######################

Expand Down Expand Up @@ -133,3 +135,6 @@ workflows:
- py310-dj42-sqlite-cms40:
requires:
- py310_base
- py310-dj42-sqlite-cms41:
requires:
- py310_base
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog

Unreleased
==========
* Django CMS 4.1 support added


1.5.0 (2024-05-16)
==================
Expand Down
12 changes: 12 additions & 0 deletions djangocms_references/compat.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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()
21 changes: 13 additions & 8 deletions djangocms_references/monkeypatch/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
13 changes: 13 additions & 0 deletions tests/requirements/dj42_cms41.txt
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 820ab37

Please sign in to comment.