Skip to content

Commit

Permalink
feat: add support for Django 5.0 and 5.1 (#429)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
fsbraun authored Oct 28, 2024
1 parent 85b0182 commit 07f9ccb
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 23 deletions.
31 changes: 23 additions & 8 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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'
]
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 14 additions & 4 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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_<field>_from_request" for each extra grouping field.
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
{% include "admin/djangocms_versioning/versioning_buttons.html" %}
<li>
{% get_preview_url original as admin_url %}
<a href="{{ admin_url }}" target="_parent">{% trans "Preview" %}</a>
<a href="{{ admin_url }}" onclick="window.parent.CMS.API.Sideframe.close()" target="_parent">
{% trans "Preview" %}
</a>
</li>
{% endblock %}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion djangocms_versioning/test_utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/requirements/dj32_cms41.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/requirements/dj42_cms41.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion tests/test_cms_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_integration_with_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 07f9ccb

Please sign in to comment.