Skip to content

Commit

Permalink
feat: django 4.2, CMS 4.1 and Python 3.10 compatibility (#50)
Browse files Browse the repository at this point in the history
* feat: django 4.2, CMS 4.1 and Python 3.10 compatibility

* fix: fix circleci config

* fix: fix tox.ini

* fix: fix flake8 and isort errors

* fix: fix isort errors
  • Loading branch information
joshyu authored Mar 6, 2024
1 parent 11cf8df commit b5b83d6
Show file tree
Hide file tree
Showing 20 changed files with 107 additions and 99 deletions.
99 changes: 46 additions & 53 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
version: 2.0

py37default: &py37default
docker:
- image: circleci/python:3.7
steps:
- setup_remote_docker:
docker_layer_caching: false
- checkout
- attach_workspace:
at: /tmp/images
- run: docker load -i /tmp/images/py37.tar || true
- run: docker run py37 tox -e $CIRCLE_JOB

py38default: &py38default
docker:
- image: circleci/python:3.8
Expand All @@ -36,10 +24,17 @@ py39default: &py39default
- run: docker load -i /tmp/images/py39.tar || true
- run: docker run py39 tox -e $CIRCLE_JOB


py37_requires: &py37_requires
requires:
- py37_base
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

py38_requires: &py38_requires
requires:
Expand All @@ -49,20 +44,11 @@ py39_requires: &py39_requires
requires:
- py39_base

py310_requires: &py310_requires
requires:
- py310_base

jobs:
py37_base:
docker:
- image: circleci/python:3.7
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: false
- run: docker build -f .circleci/Dockerfile --build-arg PYTHON_VERSION=3.7 -t py37 .
- run: mkdir images
- run: docker save -o images/py37.tar py37
- persist_to_workspace:
root: images
paths: py37.tar
py38_base:
docker:
- image: circleci/python:3.8
Expand All @@ -89,59 +75,66 @@ jobs:
- persist_to_workspace:
root: images
paths: py39.tar

py310_base:
docker:
- image: circleci/python:3.10
steps:
- checkout
- setup_remote_docker:
docker_layer_caching: false
- run: docker build -f .circleci/Dockerfile --build-arg PYTHON_VERSION=3.10 -t py310 .
- run: mkdir images
- run: docker save -o images/py310.tar py310
- persist_to_workspace:
root: images
paths: py310.tar

flake8:
<<: *py39default
<<: *py310default
isort:
<<: *py39default
<<: *py310default

py37-dj22-sqlite-cms40:
<<: *py37default
py38-dj22-sqlite-cms40:
py38-dj32-sqlite-cms40:
<<: *py38default
py39-dj22-sqlite-cms40:
py39-dj32-sqlite-cms40:
<<: *py39default

py37-dj32-sqlite-cms40:
<<: *py37default
py38-dj32-sqlite-cms40:
py38-dj42-sqlite-cms41:
<<: *py38default
py39-dj32-sqlite-cms40:
py39-dj42-sqlite-cms41:
<<: *py39default
py310-dj42-sqlite-cms41:
<<: *py310default

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

workflows:
version: 2
build:
jobs:
- py37_base
- py38_base
- py39_base
- py310_base
- flake8:
requires:
- py39_base
- py310_base
- isort:
requires:
- py39_base
- py310_base

- py37-dj22-sqlite-cms40:
requires:
- py37_base
- py38-dj22-sqlite-cms40:
- py38-dj32-sqlite-cms40:
requires:
- py38_base
- py39-dj22-sqlite-cms40:
- py39-dj32-sqlite-cms40:
requires:
- py39_base

- py37-dj32-sqlite-cms40:
requires:
- py37_base
- py38-dj32-sqlite-cms40:
- py38-dj42-sqlite-cms41:
requires:
- py38_base
- py39-dj32-sqlite-cms40:
- py39-dj42-sqlite-cms41:
requires:
- py39_base
- py310-dj42-sqlite-cms41:
requires:
- py310_base
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Changelog

Unreleased
==========
* Python 3.10 support added
* Python 3.7 support removed
* Django 4.2 support added
* Django CMS 4.1 support added

1.4.3 (2024-02-07)
==========
Expand Down
2 changes: 0 additions & 2 deletions djangocms_references/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
__version__ = "1.4.3"

default_app_config = "djangocms_references.apps.ReferencesConfig"
6 changes: 3 additions & 3 deletions djangocms_references/compat.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from distutils.version import LooseVersion
from cms import __version__ as cms_version

import django
from packaging.version import Version


DJANGO_GTE_21 = LooseVersion(django.get_version()) >= LooseVersion("2.1")
DJANGO_CMS_4_1 = Version(cms_version) >= Version('4.1')


def is_versioning_installed():
Expand Down
16 changes: 10 additions & 6 deletions djangocms_references/monkeypatch/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from djangocms_alias import admin

from djangocms_references.compat import DJANGO_CMS_4_1


def _get_references_link(self, obj, request):
alias_content_type = ContentType.objects.get(
Expand All @@ -19,9 +21,6 @@ def _get_references_link(self, obj, request):
return render_to_string("djangocms_references/references_icon.html", {"url": url})


admin.AliasContentAdmin._get_references_link = _get_references_link


def get_list_actions(func):
"""
Add references action to alias list display
Expand All @@ -33,6 +32,11 @@ def inner(self, *args, **kwargs):
return inner


admin.AliasContentAdmin.get_list_actions = get_list_actions(
admin.AliasContentAdmin.get_list_actions
)
if not DJANGO_CMS_4_1:
admin.AliasContentAdmin._get_references_link = _get_references_link
admin.AliasContentAdmin.get_list_actions = get_list_actions(
admin.AliasContentAdmin.get_list_actions
)
else:
# TODO: add reference button for django cms 4.1
pass
1 change: 0 additions & 1 deletion djangocms_references/test_utils/app_1/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "djangocms_references.test_utils.app_1.apps.App1Config"
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
default_app_config = "djangocms_references.test_utils.nested_references_app.apps.NestedReferencesAppConfig"
6 changes: 3 additions & 3 deletions djangocms_references/urls.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from django.contrib.admin.views.decorators import staff_member_required
from django.urls import re_path
from django.urls import path

from .views import ReferencesView


app_name = "djangocms_references"
urlpatterns = [
re_path(
r"^references/(?P<content_type_id>\d+)/(?P<object_id>\d+)/$",
path(
"references/<int:content_type_id>/<int:object_id>/",
staff_member_required(ReferencesView.as_view()),
name="references-index",
)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


INSTALL_REQUIREMENTS = [
"Django>=2.2,<4.0",
"Django>=3.2,<5.0",
"django-cms"
]

Expand Down
7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import django


if django.VERSION < (4, 2): # TODO: remove when dropping support for Django < 4.2
from django.test.testcases import TransactionTestCase

TransactionTestCase.assertQuerySetEqual = TransactionTestCase.assertQuerysetEqual
3 changes: 0 additions & 3 deletions tests/requirements/dj22_cms40.txt

This file was deleted.

5 changes: 5 additions & 0 deletions tests/requirements/dj32_cms40.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-r ./requirements_base.txt

Django>=3.2,<4.0

# Unreleased django-cms 4.0 compatible packages
https://github.com/django-cms/django-cms/tarball/4.0.0#egg=django-cms
https://github.com/django-cms/djangocms-versioning/tarball/1.2.2#egg=djangocms-versioning
https://github.com/django-cms/djangocms-alias/tarball/1.11.0#egg=djangocms-alias
7 changes: 7 additions & 0 deletions tests/requirements/dj42_cms41.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-r ./requirements_base.txt

Django>=4.2,<5.0

https://github.com/django-cms/django-cms/tarball/develop-4#egg=django-cms
https://github.com/django-cms/djangocms-versioning/tarball/2.0.0#egg=djangocms-versioning
https://github.com/django-cms/djangocms-alias/tarball/2.0.0#egg=djangocms-alias
5 changes: 0 additions & 5 deletions tests/requirements/requirements_base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,3 @@ factory-boy
flake8
isort
tox

# Unreleased django-cms 4.0 compatible packages
https://github.com/django-cms/django-cms/tarball/4.0.0#egg=django-cms
https://github.com/django-cms/djangocms-versioning/tarball/1.2.2#egg=djangocms-versioning
https://github.com/django-cms/djangocms-alias/tarball/1.11.0#egg=djangocms-alias
8 changes: 8 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 @@ -8,8 +10,14 @@
from djangocms_alias.models import Alias, AliasContent, Category
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
5 changes: 2 additions & 3 deletions tests/test_cms_toolbars.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from django.conf.urls import include
from django.contrib import admin
from django.contrib.auth.models import Permission
from django.test.client import RequestFactory
from django.test.utils import override_settings
from django.urls import re_path
from django.urls import include, path, re_path

from cms.middleware.toolbar import ToolbarMiddleware
from cms.test_utils.testcases import CMSTestCase
Expand All @@ -18,7 +17,7 @@


urlpatterns = [
re_path(r"^references/", include("djangocms_references.urls")),
path("references/", include("djangocms_references.urls")),
re_path(r"^admin/", admin.site.urls),
]

Expand Down
6 changes: 0 additions & 6 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from unittest import skipIf
from unittest.mock import Mock, patch

from django.apps import apps
Expand All @@ -9,7 +8,6 @@
from cms.api import add_plugin

from djangocms_references import helpers
from djangocms_references.compat import DJANGO_GTE_21
from djangocms_references.helpers import (
_get_reference_models,
combine_querysets_of_same_models,
Expand Down Expand Up @@ -135,10 +133,6 @@ def test__get_reference_models_versioned(self):
)


@skipIf(
not DJANGO_GTE_21,
"Reliable Q object comparison is available starting with Django 2.1",
)
class GetFiltersTestCase(TestCase):
def test_get_filters_empty(self):
self.assertEqual(get_filters("foo", []), Q())
Expand Down
Loading

0 comments on commit b5b83d6

Please sign in to comment.