From 07f9ccbcbdb6f665df466c3ad24eac82a15c5b95 Mon Sep 17 00:00:00 2001 From: Fabian Braun Date: Mon, 28 Oct 2024 22:00:43 +0100 Subject: [PATCH] feat: add support for Django 5.0 and 5.1 (#429) * Replace `setup.py test` in github actions * fix: added `exclude_parameters` to `ChangeList.get_queryset` * Delay test since tested fix has not been ported back to django-cms 4.1.3 * Update tests for django 5.0, 5.1 * Update test.yml for all database setups * Update to postgres 13 for django 5.x tests * Update Changelog * Update page content factory to deliver valid x frame options * fix: Close sideframe when clicking preview button * Fix: `FuzzyInteger`'s higher limit is inclusive it turns out --- .github/workflows/test.yml | 31 ++++++++++++++----- CHANGELOG.rst | 11 +++++++ djangocms_versioning/admin.py | 18 ++++++++--- .../page/change_form.html | 4 ++- djangocms_versioning/test_utils/factories.py | 2 +- tests/requirements/dj32_cms41.txt | 2 +- tests/requirements/dj42_cms41.txt | 2 +- .../{dj40_cms41.txt => dj50_cms41.txt} | 4 +-- .../{dj41_cms41.txt => dj51_cms41.txt} | 4 +-- tests/test_cms_config.py | 2 +- tests/test_integration_with_core.py | 4 +-- 11 files changed, 61 insertions(+), 23 deletions(-) rename tests/requirements/{dj40_cms41.txt => dj50_cms41.txt} (69%) rename tests/requirements/{dj41_cms41.txt => dj51_cms41.txt} (69%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f2d50066..c4315c7a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,10 +15,15 @@ jobs: python-version: [ 3.9, "3.10", "3.11", "3.12" ] # latest release minus two requirements-file: [ dj32_cms41.txt, - dj40_cms41.txt, - dj41_cms41.txt, dj42_cms41.txt, + dj50_cms41.txt, + dj51_cms41.txt, ] + exclude: + - requirements-file: dj50_cms41.txt + python-version: 3.9 + - requirements-file: dj51_cms41.txt + python-version: 3.9 steps: - uses: actions/checkout@v4 @@ -47,14 +52,19 @@ jobs: python-version: [ 3.9, "3.10", "3.11", "3.12" ] # latest release minus two requirements-file: [ dj32_cms41.txt, - dj40_cms41.txt, - dj41_cms41.txt, dj42_cms41.txt, + dj50_cms41.txt, + dj51_cms41.txt, ] + exclude: + - requirements-file: dj50_cms41.txt + python-version: 3.9 + - requirements-file: dj51_cms41.txt + python-version: 3.9 services: postgres: - image: postgres:12 + image: postgres:13 env: POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres @@ -93,10 +103,15 @@ jobs: python-version: [ 3.9, "3.10", "3.11", "3.12" ] # latest release minus two requirements-file: [ dj32_cms41.txt, - dj40_cms41.txt, - dj41_cms41.txt, dj42_cms41.txt, + dj50_cms41.txt, + dj51_cms41.txt, ] + exclude: + - requirements-file: dj50_cms41.txt + python-version: 3.9 + - requirements-file: dj51_cms41.txt + python-version: 3.9 services: mysql: @@ -135,7 +150,7 @@ jobs: fail-fast: false matrix: python-version: ['3.11'] - requirements-file: ['dj42_cms41.txt'] + requirements-file: ['dj51_cms41.txt'] cms-version: [ 'https://github.com/django-cms/django-cms/archive/develop-4.tar.gz' ] diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3b6d6f82..92f7272c 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -5,11 +5,22 @@ Changelog 2.1.0 (2024-07-12) ================== +* feat: add support for Django 5.0 and 5.1 (#429) by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/429 * feat: Add versioning actions to settings (admin change view) of versioned objects by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/408 * fix: Remove workaround for page-specific rendering by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/411 * fix: Compare versions' back button sometimes returns to invalid URL by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/413 +* feat: Add versioning actions to settings (admin change view) of versioned objects by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/408 +* feat: Optimize db evaluation by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/416 +* feat: Prefetch page content version objects for faster page tree by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/418 +* fix: Remove workaround for page-specific rendering by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/411 +* fix: Compare versions' back button sometimes returns to invalid URL by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/413 +* fix: Preparation for changes in django CMS 4.2 by @jrief in https://github.com/django-cms/djangocms-versioning/pull/419 +* fix: Unnecessary complexity in ``current_content`` query set by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/417 +* fix: get_page_content retrieved non page-content objects from the toolbar by @fsbraun in https://github.com/django-cms/djangocms-versioning/pull/423 + + **Full Changelog**: https://github.com/django-cms/djangocms-versioning/compare/2.0.2...2.1.0 2.0.2 (2024-05-03) diff --git a/djangocms_versioning/admin.py b/djangocms_versioning/admin.py index 77b1748b..84e89ce3 100644 --- a/djangocms_versioning/admin.py +++ b/djangocms_versioning/admin.py @@ -61,9 +61,14 @@ class VersioningChangeListMixin: """Mixin used for ChangeList classes of content models.""" - def get_queryset(self, request): + def get_queryset(self, request, exclude_parameters=None): """Limit the content model queryset to the latest versions only.""" - queryset = super().get_queryset(request) + if exclude_parameters: + # Django 5.0+ (facet support) + queryset = super().get_queryset(request, exclude_parameters) + else: + # Django 4.2 compatible get_queryset + queryset = super().get_queryset(request) versionable = versionables.for_content(queryset.model) """Check if there is a method "self.get__from_request" for each extra grouping field. @@ -557,7 +562,7 @@ def get_grouping_field_filters(self, request): if value is not None: yield field, value - def get_queryset(self, request): + def get_queryset(self, request, exclude_parameters=None): """Adds support for querying the version model by grouping fields. Filters by the value of grouping fields (specified in VersionableItem @@ -567,7 +572,12 @@ def get_queryset(self, request): for specifying filters that work without being shown in the UI along with filter choices. """ - queryset = super().get_queryset(request) + if exclude_parameters: + # Django 5.0+ (facet support) + queryset = super().get_queryset(request, exclude_parameters) + else: + # Django 4.2 compatible get_queryset + queryset = super().get_queryset(request) content_model = self.model_admin.model._source_model versionable = versionables.for_content(content_model) filters = dict(self.get_grouping_field_filters(request)) diff --git a/djangocms_versioning/templates/admin/djangocms_versioning/page/change_form.html b/djangocms_versioning/templates/admin/djangocms_versioning/page/change_form.html index 925c1845..43039a22 100644 --- a/djangocms_versioning/templates/admin/djangocms_versioning/page/change_form.html +++ b/djangocms_versioning/templates/admin/djangocms_versioning/page/change_form.html @@ -19,7 +19,9 @@ {% include "admin/djangocms_versioning/versioning_buttons.html" %}
  • {% get_preview_url original as admin_url %} - {% trans "Preview" %} + + {% trans "Preview" %} +
  • {% endblock %} diff --git a/djangocms_versioning/test_utils/factories.py b/djangocms_versioning/test_utils/factories.py index 0b62dc59..2eb97417 100644 --- a/djangocms_versioning/test_utils/factories.py +++ b/djangocms_versioning/test_utils/factories.py @@ -226,7 +226,7 @@ class PageContentFactory(AbstractContentFactory): soft_root = FuzzyChoice([True, False]) limit_visibility_in_menu = constants.VISIBILITY_USERS template = "page.html" - xframe_options = FuzzyInteger(0, 25) + xframe_options = FuzzyInteger(0, 3) class Meta: model = PageContent diff --git a/tests/requirements/dj32_cms41.txt b/tests/requirements/dj32_cms41.txt index b81e33fd..aaafdfa5 100644 --- a/tests/requirements/dj32_cms41.txt +++ b/tests/requirements/dj32_cms41.txt @@ -4,5 +4,5 @@ django-cms>=4.1,<4.2 Django>=3.2,<4.0 django-classy-tags -django-fsm>=2.6 +django-fsm>=2.6,<3 django-sekizai diff --git a/tests/requirements/dj42_cms41.txt b/tests/requirements/dj42_cms41.txt index 3546934e..bf600a57 100644 --- a/tests/requirements/dj42_cms41.txt +++ b/tests/requirements/dj42_cms41.txt @@ -4,5 +4,5 @@ django-cms>=4.1,<4.2 Django>=4.2,<5 django-classy-tags -django-fsm>=2.6 +django-fsm>=2.6,<3 django-sekizai diff --git a/tests/requirements/dj40_cms41.txt b/tests/requirements/dj50_cms41.txt similarity index 69% rename from tests/requirements/dj40_cms41.txt rename to tests/requirements/dj50_cms41.txt index 08f469ca..4326bfd7 100644 --- a/tests/requirements/dj40_cms41.txt +++ b/tests/requirements/dj50_cms41.txt @@ -2,7 +2,7 @@ django-cms>=4.1,<4.2 -Django>=4.0,<4.1 +Django>=5.0,<5.1 django-classy-tags -django-fsm>=2.6 +django-fsm>=2.6,<3 django-sekizai diff --git a/tests/requirements/dj41_cms41.txt b/tests/requirements/dj51_cms41.txt similarity index 69% rename from tests/requirements/dj41_cms41.txt rename to tests/requirements/dj51_cms41.txt index 08e4d41b..14b5770e 100644 --- a/tests/requirements/dj41_cms41.txt +++ b/tests/requirements/dj51_cms41.txt @@ -2,7 +2,7 @@ django-cms>=4.1,<4.2 -Django>=4.1,<4.2 +Django>=5.1,<5.2 django-classy-tags -django-fsm>=2.6 +django-fsm>=2.6,<3 django-sekizai diff --git a/tests/test_cms_config.py b/tests/test_cms_config.py index 13153e12..001f4520 100644 --- a/tests/test_cms_config.py +++ b/tests/test_cms_config.py @@ -119,7 +119,7 @@ def test_changing_slug_changes_page_url(self): form = ChangePageForm(data, instance=self.content) form._request = request form._site = self.site - self.assertEqual(form.is_valid(), True) + self.assertTrue(form.is_valid(), f"Form errors: {form.errors}") form.save() page = Page.objects.get(pk=self.page.pk) diff --git a/tests/test_integration_with_core.py b/tests/test_integration_with_core.py index d4afcfb4..ff66110e 100644 --- a/tests/test_integration_with_core.py +++ b/tests/test_integration_with_core.py @@ -280,9 +280,9 @@ def setUp(self): self.page.save() - @skipIf(cms_version < "4.1.3", "Bug only fixed in django CMS 4.1.3") + @skipIf(cms_version < "4.1.4", "Bug only fixed in django CMS 4.1.4") def test_get_admin_url_for_language(self): - """Regression fixed that made unpublished and archived versions invisivle to get_admin_url_for_language + """Regression fixed that made unpublished and archived versions invisible to get_admin_url_for_language template tag. See: https://github.com/django-cms/django-cms/pull/7967""" from django.template import Template