From fb0a824268df3d27b0e006a5f1310ab94f6a7e6c Mon Sep 17 00:00:00 2001 From: Josh Yu Date: Tue, 5 Nov 2024 09:15:05 +0800 Subject: [PATCH 1/5] feat: CMS 4.1 compatible intiial commit --- .github/workflows/test.yml | 6 ++++-- CHANGELOG.rst | 5 +++++ djangocms_url_manager/models.py | 16 ++++------------ tests/requirements/dj42_cms41.txt | 8 ++++++++ tox.ini | 8 +++----- 5 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 tests/requirements/dj42_cms41.txt diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8ec9ce4..fea348c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,10 +10,11 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.8, 3.9, '3.10' ] # latest release minus two + python-version: [ 3.9, '3.10' ] # latest release minus two requirements-file: [ dj32_cms40.txt, dj42_cms40.txt, + dj42_cms41.txt, ] os: [ ubuntu-20.04, @@ -43,10 +44,11 @@ jobs: strategy: fail-fast: false matrix: - python-version: [ 3.8, 3.9, '3.10' ] # latest release minus two + python-version: [ 3.9, '3.10' ] # latest release minus two requirements-file: [ dj32_cms40.txt, dj42_cms40.txt, + dj42_cms41.txt, ] steps: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 951ad47..bc1119e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ Changelog ========= +Unleased +======== +* Python 3.8 support removed +* Django CMS 4.1 support added + 1.2.0 (2024-05-16) ========== * Python 3.10 support added diff --git a/djangocms_url_manager/models.py b/djangocms_url_manager/models.py index 57372bf..daaf2cb 100644 --- a/djangocms_url_manager/models.py +++ b/djangocms_url_manager/models.py @@ -3,7 +3,6 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site from django.db import models -from django.db.models import Q from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ @@ -116,21 +115,14 @@ def get_content_queryset(self): raise NotImplementedError("Models implementing AbstractUrlGrouper should implement get_content_queryset") def get_content(self, show_draft_content=False): - qs = self.get_content_queryset() - - if show_draft_content and is_versioning_enabled(): - from djangocms_versioning.constants import DRAFT, PUBLISHED - from djangocms_versioning.helpers import remove_published_where - - # Ensure that we are getting the latest valid content, the top most version can become - # archived with a previous version re-published - qs = remove_published_where(qs) - qs = qs.filter(Q(versions__state=DRAFT) | Q(versions__state=PUBLISHED)).order_by('-versions__created') + qs = self.get_content_queryset(show_draft_content) return qs.first() class UrlGrouper(AbstractUrlGrouper): - def get_content_queryset(self): + def get_content_queryset(self, show_draft_content=False): + if hasattr(Url, "admin_manager") and show_draft_content: + return Url.admin_manager.current_content().filter(url_grouper=self) return Url.objects.filter(url_grouper=self) diff --git a/tests/requirements/dj42_cms41.txt b/tests/requirements/dj42_cms41.txt new file mode 100644 index 0000000..688cf3d --- /dev/null +++ b/tests/requirements/dj42_cms41.txt @@ -0,0 +1,8 @@ +-r requirements_base.txt + +Django>=4.2,<5.0 +django-cms>=4.1.0 +djangocms-versioning>2.0 + +# Unreleased django 4.2 compatible packages +https://github.com/django-cms/djangocms-moderation/tarball/master#egg=djangocms-moderation \ No newline at end of file diff --git a/tox.ini b/tox.ini index f70933e..b6b980f 100644 --- a/tox.ini +++ b/tox.ini @@ -2,7 +2,7 @@ envlist = flake8 isort - py{38,39,'3.10'}-dj{32,42}-sqlite-cms40-{default,versioning} + py{39,3.10}-dj{32,42}-sqlite-cms{40,41}-{default,versioning} skip_missing_interpreters=True @@ -13,12 +13,10 @@ deps = -r {toxinidir}/tests/requirements/requirements_base.txt dj32: -r {toxinidir}/tests/requirements/django-3_2.txt - dj42: -r {toxinidir}/tests/requirements/dj42_cms40.txt - - cms40: https://github.com/divio/django-cms/archive/release/4.0.x.zip + dj42-cms40: -r {toxinidir}/tests/requirements/dj42_cms40.txt + dj42-cms41: -r {toxinidir}/tests/requirements/dj42_cms41.txt basepython = - py38: python3.8 py39: python3.9 py310: python3.10 From 85c604efbe2dd08d5ebf251b77d58717886d151a Mon Sep 17 00:00:00 2001 From: Josh Yu Date: Tue, 5 Nov 2024 09:33:35 +0800 Subject: [PATCH 2/5] fix: add checking --- djangocms_url_manager/compat.py | 3 +++ djangocms_url_manager/models.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/djangocms_url_manager/compat.py b/djangocms_url_manager/compat.py index a4bae70..d14af85 100644 --- a/djangocms_url_manager/compat.py +++ b/djangocms_url_manager/compat.py @@ -2,8 +2,11 @@ from packaging.version import Version +from cms import __version__ as CMS_VERSION + DJANGO_4_1 = Version(django.get_version()) < Version('4.2') +CMS_41 = Version("4.1") <= Version(CMS_VERSION) def get_page_placeholders(page, language=None): diff --git a/djangocms_url_manager/models.py b/djangocms_url_manager/models.py index daaf2cb..60f5a6e 100644 --- a/djangocms_url_manager/models.py +++ b/djangocms_url_manager/models.py @@ -3,6 +3,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site from django.db import models +from django.db.models import Q from django.utils.functional import cached_property from django.utils.translation import gettext_lazy as _ @@ -10,7 +11,7 @@ from cms.utils.i18n import get_default_language_for_site from djangocms_attributes_field.fields import AttributesField - +from djangocms_url_manager.compat import CMS_41 from djangocms_url_manager.utils import is_versioning_enabled @@ -116,12 +117,20 @@ def get_content_queryset(self): def get_content(self, show_draft_content=False): qs = self.get_content_queryset(show_draft_content) + if not CMS_41 and show_draft_content and is_versioning_enabled(): + from djangocms_versioning.constants import DRAFT, PUBLISHED + from djangocms_versioning.helpers import remove_published_where + + # Ensure that we are getting the latest valid content, the top most version can become + # archived with a previous version re-published + qs = remove_published_where(qs) + qs = qs.filter(Q(versions__state=DRAFT) | Q(versions__state=PUBLISHED)).order_by('-versions__created') return qs.first() class UrlGrouper(AbstractUrlGrouper): def get_content_queryset(self, show_draft_content=False): - if hasattr(Url, "admin_manager") and show_draft_content: + if CMS_41 and hasattr(Url, "admin_manager") and show_draft_content: return Url.admin_manager.current_content().filter(url_grouper=self) return Url.objects.filter(url_grouper=self) From 1428d8e69139b40c4d56a18fb1736fb50f6f3b62 Mon Sep 17 00:00:00 2001 From: Josh Yu Date: Tue, 5 Nov 2024 10:29:24 +0800 Subject: [PATCH 3/5] fix: 302 error --- tests/test_versioning_integration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_versioning_integration.py b/tests/test_versioning_integration.py index ed458b2..d71c1ef 100644 --- a/tests/test_versioning_integration.py +++ b/tests/test_versioning_integration.py @@ -184,7 +184,7 @@ def test_edit_endpoint_published_page_rendering_published_url(self): request_url = get_object_edit_url(self.published_pagecontent, self.language) with self.login_user_context(self.user): - response = self.client.get(request_url) + response = self.client.get(request_url, follow=True) self.assertContains(response, "some/path/") @@ -216,7 +216,7 @@ def test_edit_endpoint_published_page_rendering_draft_url(self): request_url = get_object_edit_url(self.published_pagecontent, self.language) with self.login_user_context(self.user): - response = self.client.get(request_url) + response = self.client.get(request_url, follow=True) self.assertContains(response, "some/path/") From aef3389df7fbdeff49c25aaba30002f0770ca33a Mon Sep 17 00:00:00 2001 From: Josh Yu Date: Tue, 5 Nov 2024 14:59:24 +0800 Subject: [PATCH 4/5] fix: Update `djangocms_url_manager/models.py` Co-authored-by: Fabian Braun --- djangocms_url_manager/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/djangocms_url_manager/models.py b/djangocms_url_manager/models.py index 60f5a6e..12e2b51 100644 --- a/djangocms_url_manager/models.py +++ b/djangocms_url_manager/models.py @@ -130,7 +130,7 @@ def get_content(self, show_draft_content=False): class UrlGrouper(AbstractUrlGrouper): def get_content_queryset(self, show_draft_content=False): - if CMS_41 and hasattr(Url, "admin_manager") and show_draft_content: + if hasattr(Url, "admin_manager") and show_draft_content: return Url.admin_manager.current_content().filter(url_grouper=self) return Url.objects.filter(url_grouper=self) From 9293da3e4acc1c701e5c329fdd2c271c69a53692 Mon Sep 17 00:00:00 2001 From: Josh Yu Date: Tue, 5 Nov 2024 15:02:55 +0800 Subject: [PATCH 5/5] fix: isort issues --- djangocms_url_manager/compat.py | 4 ++-- djangocms_url_manager/models.py | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/djangocms_url_manager/compat.py b/djangocms_url_manager/compat.py index d14af85..6493263 100644 --- a/djangocms_url_manager/compat.py +++ b/djangocms_url_manager/compat.py @@ -1,9 +1,9 @@ import django -from packaging.version import Version - from cms import __version__ as CMS_VERSION +from packaging.version import Version + DJANGO_4_1 = Version(django.get_version()) < Version('4.2') CMS_41 = Version("4.1") <= Version(CMS_VERSION) diff --git a/djangocms_url_manager/models.py b/djangocms_url_manager/models.py index 12e2b51..942f11c 100644 --- a/djangocms_url_manager/models.py +++ b/djangocms_url_manager/models.py @@ -11,6 +11,7 @@ from cms.utils.i18n import get_default_language_for_site from djangocms_attributes_field.fields import AttributesField + from djangocms_url_manager.compat import CMS_41 from djangocms_url_manager.utils import is_versioning_enabled