Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/cms41 compat #164

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.8, 3.9, '3.10' ]
python-version: [ 3.9, '3.10' ]
requirements-file: [
dj42_cms40.txt,
dj32_cms40.txt,
dj42_cms41.txt,
]

steps:
Expand Down
57 changes: 49 additions & 8 deletions djangocms_navigation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.template.response import TemplateResponse
from django.urls import path, re_path, reverse, reverse_lazy
from django.utils.html import format_html, format_html_join
from django.utils.safestring import mark_safe
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
from django.views.i18n import JavaScriptCatalog
Expand All @@ -26,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
Expand All @@ -36,11 +37,22 @@
from .views import ContentObjectSelect2View, MessageStorageView


menuitem_admin_class = [TreeAdmin]

try:
from djangocms_version_locking.helpers import (
content_is_unlocked_for_user,
version_is_locked,
)
if CMS_41:
from cms.admin.utils import ChangeListActionsMixin

from djangocms_versioning.helpers import (
content_is_unlocked_for_user,
version_is_locked,
)
menuitem_admin_class.insert(0, ChangeListActionsMixin)
else:
from djangocms_version_locking.helpers import (
content_is_unlocked_for_user,
version_is_locked,
)

using_version_lock = True
LOCK_MESSAGE = _(
Expand Down Expand Up @@ -79,7 +91,7 @@ class MenuContentAdmin(ExtendedVersionAdminMixin, admin.ModelAdmin):

class Media:
js = ("admin/js/jquery.init.js", "djangocms_versioning/js/actions.js",)
css = {"all": ("djangocms_versioning/css/actions.css", "djangocms_version_locking/css/version-locking.css",)}
css = {"all": ("djangocms_version_locking/css/version-locking.css",)}

def _list_actions(self, request):
"""
Expand Down Expand Up @@ -138,6 +150,8 @@ def get_list_display(self, request):
def is_locked(self, obj):
version = self.get_version(obj)
if version.state == DRAFT and version_is_locked(version):
if CMS_41:
return mark_safe('<span class="cms-icon cms-icon-lock"></span>')
return render_to_string("djangocms_version_locking/admin/locked_icon.html")
return ""

Expand Down Expand Up @@ -185,6 +199,15 @@ def _get_main_navigation_link(self, obj, request, disabled=False):
if obj.menu.main_navigation:
disabled = True

if CMS_41:
return self.admin_action_button(
url=main_navigation_url,
icon="home",
title=_("Make Main Navigation"),
name="make-main-navigation",
disabled=disabled,
)

return render_to_string(
"admin/djangocms_navigation/icons/main_navigation.html",
{"url": main_navigation_url, "disabled": disabled}
Expand Down Expand Up @@ -262,7 +285,7 @@ def get_menuitem_link(self, obj):


@admin.register(MenuItem)
class MenuItemAdmin(TreeAdmin):
class MenuItemAdmin(*menuitem_admin_class):
form = MenuItemForm
menu_content_model = MenuContent
menu_model = Menu
Expand All @@ -276,7 +299,6 @@ class MenuItemAdmin(TreeAdmin):
class Media:
css = {
"all": (
"djangocms_versioning/css/actions.css",
"djangocms_navigation/css/navigation_admin_changelist.css",
)
}
Expand Down Expand Up @@ -389,6 +411,16 @@ def _get_edit_link(self, obj, request, disabled=False):
args=[request.menu_content_id, obj.id]
)

if CMS_41:
return self.admin_action_button(
edit_url,
icon="pencil",
title=_("Edit"),
name="edit",
disabled=disabled,
keepsideframe=False,
)

return render_to_string(
"djangocms_versioning/admin/icons/edit_icon.html",
{"url": edit_url, "disabled": disabled, "object_id": obj.id}
Expand All @@ -402,6 +434,15 @@ def _get_delete_link(self, obj, request, disabled=False):
args=[request.menu_content_id, obj.id]
)

if CMS_41:
return self.admin_action_button(
delete_url,
icon="bin",
title=_("Discord"),
name="discard",
disabled=disabled,
)

return render_to_string(
"djangocms_versioning/admin/discard_icon.html",
{"discard_url": delete_url, "disabled": disabled, "object_id": obj.id},
Expand Down
3 changes: 3 additions & 0 deletions djangocms_navigation/compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from cms import __version__ as CMS_VERSION

from packaging.version import Version
from treebeard import __version__ as treebeard_version


TREEBEARD_4_5 = Version(treebeard_version) < Version('4.6')
CMS_41 = Version("4.1") <= Version(CMS_VERSION)
6 changes: 6 additions & 0 deletions djangocms_navigation/test_utils/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from djangocms_versioning.models import Version
from factory.fuzzy import FuzzyChoice, FuzzyInteger, FuzzyText

from ..compat import CMS_41
from ..models import Menu, MenuContent, MenuItem


Expand Down Expand Up @@ -125,9 +126,14 @@ 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

if not CMS_41 and 'locked_by' in kwargs:
kwargs.pop('locked_by')

PageVersionFactory(content=self, **kwargs)


Expand Down
22 changes: 16 additions & 6 deletions djangocms_navigation/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from djangocms_versioning.constants import DRAFT, PUBLISHED
from djangocms_versioning.helpers import remove_published_where

from .compat import CMS_41


def get_admin_name(model, name):
name = '{}_{}_{}'.format(
Expand Down Expand Up @@ -97,9 +99,17 @@ 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
"""
page_contents = PageContent.objects.filter(
page=obj,
language=language,
versions__state__in=[DRAFT, PUBLISHED]
).order_by("-versions__pk")
return remove_published_where(page_contents).first()
if CMS_41:
page_contents = PageContent.admin_manager.filter(
page=obj,
language=language,
versions__state__in=[DRAFT, PUBLISHED]
).order_by("-versions__pk")
return page_contents.first()
else:
page_contents = PageContent.objects.filter(
page=obj,
language=language,
versions__state__in=[DRAFT, PUBLISHED]
).order_by("-versions__pk")
return remove_published_where(page_contents).first()
15 changes: 11 additions & 4 deletions djangocms_navigation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from djangocms_versioning.constants import ARCHIVED, UNPUBLISHED

from djangocms_navigation.compat import CMS_41
from djangocms_navigation.utils import is_model_supported, supported_models


Expand Down Expand Up @@ -38,10 +39,16 @@ def get(self, request, *args, **kwargs):

# Removing unpublished pages from queryset
if model == Page:
queryset_data = [
page for page in queryset_data
if not getattr(page.get_title_obj().versions.first(), "state", None) in [ARCHIVED, UNPUBLISHED]
]
if CMS_41:
queryset_data = [
page for page in queryset_data
if getattr(page.get_content_obj().versions.first(), "state", None) not in [ARCHIVED, UNPUBLISHED]
]
else:
queryset_data = [
page for page in queryset_data
if getattr(page.get_title_obj().versions.first(), "state", None) not in [ARCHIVED, UNPUBLISHED]
]

data = {
"results": [{"text": str(obj), "id": obj.pk} for obj in queryset_data]
Expand Down
21 changes: 21 additions & 0 deletions tests/requirements/dj42_cms41.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
beautifulsoup4
coverage
django-app-helper
django-classy-tags
django-sekizai
factory_boy
flake8
isort
lxml
tox

django>=4.2,<5.0
django-treebeard>=4.6.0
django-cms>=4.1.0
djangocms-text-ckeditor==5.1.5
djangocms-versioning==2.1.0
https://github.com/FreemanPancake/djangocms-version-locking/tarball/feature/djangocms4x-compat#egg=djangocms-version-locking
https://github.com/django-cms/djangocms-moderation/tarball/master#egg=djangocms-moderation
https://github.com/FidelityInternational/djangocms-references/tarball/feat/cms41-compat#egg=djangocms-references
https://github.com/django-cms/djangocms-alias/tarball/master#egg=djangocms-alias
https://github.com/django-cms/djangocms-snippet/tarball/master#egg=djangocms-snippet
Loading
Loading