diff --git a/djangocms_navigation/admin.py b/djangocms_navigation/admin.py index 3c30030db..1a0cc4171 100644 --- a/djangocms_navigation/admin.py +++ b/djangocms_navigation/admin.py @@ -27,7 +27,7 @@ from djangocms_versioning.models import Version from treebeard.admin import TreeAdmin -from .compat import TREEBEARD_4_5 +from .compat import CMS_41, TREEBEARD_4_5 from .conf import TREE_MAX_RESULT_PER_PAGE_COUNT from .filters import LanguageFilter from .forms import MenuContentForm, MenuItemForm @@ -36,14 +36,13 @@ from .utils import is_versioning_enabled, purge_menu_cache, reverse_admin_name from .views import ContentObjectSelect2View, MessageStorageView -from .compat import CMS_41 - menuitem_admin_class = [TreeAdmin] try: if CMS_41: from cms.admin.utils import ChangeListActionsMixin + from djangocms_versioning.helpers import ( content_is_unlocked_for_user, version_is_locked, diff --git a/djangocms_navigation/compat.py b/djangocms_navigation/compat.py index dd9bb89d5..2711c8d79 100644 --- a/djangocms_navigation/compat.py +++ b/djangocms_navigation/compat.py @@ -1,8 +1,8 @@ +from cms import __version__ as CMS_VERSION + from packaging.version import Version from treebeard import __version__ as treebeard_version -from cms import __version__ as CMS_VERSION - TREEBEARD_4_5 = Version(treebeard_version) < Version('4.6') CMS_41 = Version("4.1") <= Version(CMS_VERSION) diff --git a/djangocms_navigation/test_utils/factories.py b/djangocms_navigation/test_utils/factories.py index 9f0428b3e..fc644f1d4 100644 --- a/djangocms_navigation/test_utils/factories.py +++ b/djangocms_navigation/test_utils/factories.py @@ -126,7 +126,7 @@ class PageContentWithVersionFactory(PageContentFactory): def version(self, create, extracted, **kwargs): # NOTE: Use this method as below to define version attributes: # PageContentWithVersionFactory(version__label='label1') - + if not create: # Simple build, do nothing. return diff --git a/djangocms_navigation/utils.py b/djangocms_navigation/utils.py index 493c0f901..bfb168d21 100644 --- a/djangocms_navigation/utils.py +++ b/djangocms_navigation/utils.py @@ -99,7 +99,7 @@ def get_latest_page_content_for_page_grouper(obj, language): :return: A queryset if an item exists, or None if not. :rtype: Queryset object, or None """ - if CMS_41: + if CMS_41: page_contents = PageContent.admin_manager.filter( page=obj, language=language, diff --git a/djangocms_navigation/views.py b/djangocms_navigation/views.py index b65b72e16..acf5e5b6f 100644 --- a/djangocms_navigation/views.py +++ b/djangocms_navigation/views.py @@ -8,10 +8,11 @@ from cms.models import Page from cms.utils import get_current_site, get_language_from_request -from djangocms_navigation.utils import is_model_supported, supported_models -from djangocms_navigation.compat import CMS_41 from djangocms_versioning.constants import ARCHIVED, UNPUBLISHED +from djangocms_navigation.compat import CMS_41 +from djangocms_navigation.utils import is_model_supported, supported_models + class ContentObjectSelect2View(View): menu_content_model = None diff --git a/tests/test_admin.py b/tests/test_admin.py index bc4be2241..b1a7d557e 100644 --- a/tests/test_admin.py +++ b/tests/test_admin.py @@ -2,12 +2,9 @@ import importlib import json import sys - -from bs4 import BeautifulSoup from unittest import skipIf, skipUnless from unittest.mock import patch - from django.contrib import admin from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType @@ -23,6 +20,7 @@ from cms.toolbar.utils import get_object_preview_url from cms.utils.compat import DJANGO_4_1 +from bs4 import BeautifulSoup from djangocms_versioning.constants import DRAFT, PUBLISHED, UNPUBLISHED from djangocms_versioning.exceptions import ConditionFailed from djangocms_versioning.helpers import version_list_url @@ -33,13 +31,13 @@ MenuItemAdmin, MenuItemChangeList, ) -from djangocms_navigation.compat import TREEBEARD_4_5 +from djangocms_navigation.compat import CMS_41, TREEBEARD_4_5 from djangocms_navigation.models import Menu, MenuContent, MenuItem from djangocms_navigation.test_utils import factories -from djangocms_navigation.compat import CMS_41 from .utils import UsefulAssertsMixin, disable_versioning_for_navigation + versioning_substr = "" if CMS_41: from cms.api import create_page_content # noqa: F401 diff --git a/tests/test_utils.py b/tests/test_utils.py index 0e89b0c48..990205e43 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -15,7 +15,6 @@ UNPUBLISHED, ) -from djangocms_navigation.compat import CMS_41 from djangocms_navigation.models import MenuContent from djangocms_navigation.test_utils import factories from djangocms_navigation.test_utils.app_1.models import TestModel1, TestModel2 diff --git a/tests/test_views.py b/tests/test_views.py index e7e2a802b..83151d7e7 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -300,7 +300,13 @@ def test_with_pages_for_multiple_sites(self): site1 = Site.objects.create(name="site1.com", domain="site1.com") site2 = Site.objects.create(name="site2.com", domain="site2.com") PageContentFactory.create_batch(10, title="test", page__node__site=site1, language="en") - expected = PageContentWithVersionFactory(title="test", menu_title="site2 page", page__node__site=site2, language="en", version__state=PUBLISHED) + expected = PageContentWithVersionFactory( + title="test", + menu_title="site2 page", + page__node__site=site2, + language="en", + version__state=PUBLISHED + ) with self.login_user_context(self.superuser): response = self.client.get( @@ -350,7 +356,11 @@ def test_searching_for_page_path(self): page_contenttype_id = ContentType.objects.get_for_model(Page).id PageContentFactory.create_batch(10, language="en") expected = PageContentWithVersionFactory( - title="test", menu_title="Test search by overwritten url", page_title="test", language="en", version__state=PUBLISHED + title="test", + menu_title="Test search by overwritten url", + page_title="test", + language="en", + version__state=PUBLISHED ) # update page urls to use a randomly generated path to represent setting an overwritten url path = fake.uri_path()