Skip to content

Commit

Permalink
fix: For Django CMS 4.1.1 and later do not automatically register ver…
Browse files Browse the repository at this point in the history
…sioned CMS Menu (django-cms#388)

* fix django-cms#384: Unlock button in toolbar points onto DRAFT version

* Only by default register the versioning CMS Menu for django CMS <= 4.1.0

* Respect new ruff rule UP032

* Typos...

* Ensure tests are covering djangocms-versioning's menu

---------

Co-authored-by: Jacob Rief <[email protected]>
  • Loading branch information
fsbraun and jrief authored Mar 7, 2024
1 parent 0f6a587 commit 9071ace
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 25 deletions.
5 changes: 1 addition & 4 deletions djangocms_versioning/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,10 +1316,7 @@ def changelist_view(self, request, extra_context=None):
# Check if custom breadcrumb template defined, otherwise
# fallback on default
breadcrumb_templates = [
"admin/djangocms_versioning/{app_label}/{model_name}/versioning_breadcrumbs.html".format(
app_label=breadcrumb_opts.app_label,
model_name=breadcrumb_opts.model_name,
),
f"admin/djangocms_versioning/{breadcrumb_opts.app_label}/{breadcrumb_opts.model_name}/versioning_breadcrumbs.html",
"admin/djangocms_versioning/versioning_breadcrumbs.html",
]
extra_context["breadcrumb_template"] = select_template(breadcrumb_templates)
Expand Down
3 changes: 2 additions & 1 deletion djangocms_versioning/conf.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from cms import __version__ as CMS_VERSION
from django.conf import settings

ENABLE_MENU_REGISTRATION = getattr(
settings, "DJANGOCMS_VERSIONING_ENABLE_MENU_REGISTRATION", True
settings, "DJANGOCMS_VERSIONING_ENABLE_MENU_REGISTRATION", CMS_VERSION <= "4.1.0"
)

USERNAME_FIELD = getattr(
Expand Down
6 changes: 4 additions & 2 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ Settings for djangocms Versioning

.. py:attribute:: DJANGOCMS_VERSIONING_ENABLE_MENU_REGISTRATION
Defaults to ``True``
Defaults to ``True`` (for django CMS <= 4.1.0) and ``False``
(for django CMS > 4.1.0)

This settings specifies if djangocms-versioning should register its own
versioned CMS menu.
versioned CMS menu. This is necessary for CMS <= 4.1.0. For CMS > 4.1.0, the
django CMS core comes with a version-ready menu.

The versioned CMS menu also shows draft content in edit and preview mode.

Expand Down
1 change: 1 addition & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"PARLER_ENABLE_CACHING": False,
"LANGUAGE_CODE": "en",
"DEFAULT_AUTO_FIELD": "django.db.models.AutoField",
"DJANGOCMS_VERSIONING_ENABLE_MENU_REGISTRATION": True,
"CMS_CONFIRM_VERSION4": True,
}

Expand Down
32 changes: 14 additions & 18 deletions tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,12 +452,11 @@ def test_content_link_for_editable_object_with_no_preview_url(self):
version = factories.PageVersionFactory(content__title="test5")
with patch.object(helpers, "is_editable_model", return_value=True):
with override(version.content.language):
url = get_object_preview_url(version.content, language=version.content.language)
label = version.content
self.assertEqual(
self.site._registry[Version].content_link(version),
'<a target="_top" class="js-close-sideframe" href="{url}">{label}</a>'.format(
url=get_object_preview_url(version.content, language=version.content.language),
label=version.content
),
f'<a target="_top" class="js-close-sideframe" href="{url}">{label}</a>',
)


Expand Down Expand Up @@ -2371,9 +2370,7 @@ def test_changelist_view_displays_correct_breadcrumbs(self):
expected = """<div class="breadcrumbs">\\n<a href="/en/admin/">Home</a>\\n› """
expected += """<a href="/en/admin/polls/">Polls</a>\\n› """
expected += """<a href="/en/admin/polls/pollcontent/">Poll contents</a>\\n› """
expected += """<a href="/en/admin/polls/pollcontent/{pk}/change/">{name}</a>\\n› """.format(
pk=str(poll_content.pk), name=str(poll_content)
)
expected += f"""<a href="/en/admin/polls/pollcontent/{poll_content.pk}/change/">{str(poll_content)}</a>\\n› """
expected += """Versions\\n</div>"""
self.assertEqual(str(breadcrumb_html), expected)

Expand Down Expand Up @@ -2422,12 +2419,11 @@ def test_changelist_view_displays_correct_breadcrumbs_for_extra_grouping_values(
breadcrumb_html = soup.find("div", class_="breadcrumbs")
# Assert the breadcrumbs - we should have ignored the French one
# and put the English one in the breadcrumbs
pk = page_content_en.pk
expected = """<div class="breadcrumbs">\\n<a href="/en/admin/">Home</a>\\n› """
expected += """<a href="/en/admin/cms/">django CMS</a>\\n› """
expected += """<a href="/en/admin/cms/pagecontent/">Page contents</a>\\n› """
expected += """<a href="/en/admin/cms/pagecontent/{pk}/change/">{name}</a>\\n› """.format(
pk=str(page_content_en.pk), name=str(page_content_en)
)
expected += f"""<a href="/en/admin/cms/pagecontent/{pk}/change/">{page_content_en}</a>\\n› """
expected += """Versions\\n</div>"""
self.assertEqual(str(breadcrumb_html), expected)

Expand Down Expand Up @@ -2673,10 +2669,10 @@ def test_extended_version_change_list_display_renders_from_provided_list_display
self.assertEqual(200, response.status_code)

# Check list_display item is rendered
self.assertContains(response, '<a href="/en/admin/polls/pollcontent/{}/change/">[TEST]{}</a>'.format(
content.id,
content.text
))
self.assertContains(
response,
f'<a href="/en/admin/polls/pollcontent/{content.id}/change/">[TEST]{content.text}</a>'
)
# Check list_action links are rendered
self.assertContains(response, "cms-action-btn")
self.assertContains(response, "cms-action-preview")
Expand Down Expand Up @@ -2901,10 +2897,10 @@ def test_extended_grouper_change_list_display_renders_from_provided_list_display
# Check response is valid
self.assertEqual(200, response.status_code)
# Check list_display item is rendered
self.assertContains(response, '<a href="/en/admin/polls/poll/{}/change/">[TEST]{}</a>'.format(
content.poll.id,
content.text
))
self.assertContains(
response,
f'<a href="/en/admin/polls/poll/{content.poll.id}/change/">[TEST]{content.text}</a>',
)
# Check list_action links are rendered
self.assertContains(response, "cms-action-btn")
self.assertContains(response, "cms-action-view")
Expand Down

0 comments on commit 9071ace

Please sign in to comment.