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

Changes made for cms4.1 compatible #96

Open
wants to merge 18 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
6 changes: 3 additions & 3 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
python-version: '3.11'
- name: Install flake8
run: pip install --upgrade flake8
- name: Run flake8
Expand All @@ -29,10 +29,10 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
python-version: '3.11'
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v1
with:
linters: isort
run: isort -c -rc -df ./
run: isort --check-only --diff ./
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.8, 3.9, '3.10' ] # latest release minus two
python-version: [ 3.9, '3.10', '3.11' ] # latest release minus two
requirements-file: [
dj32_cms40.txt,
dj42_cms40.txt,
dj42_cms41.txt,
]

steps:
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
=========

Unreleased
==========
* Dropped support for Django < 4.2
* Dropped support for Django CMS < 4.1
* Add support for Django CMS 4.1
* Added support for Python 3.11
* remove action burger menu from this addon, as this has been integrated in djangocms-version-locking.

1.7.1 (2024-06-06)
=================
* Fixed edit link in pageadmin to close sideframe
Expand Down
157 changes: 93 additions & 64 deletions djangocms_pageadmin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,26 @@
HttpResponseRedirect,
)
from django.shortcuts import redirect, render
from django.template.loader import render_to_string
from django.urls import path, re_path, reverse
from django.utils.decorators import method_decorator
from django.utils.html import format_html, format_html_join
from django.utils.safestring import mark_safe
from django.utils.translation import get_language, gettext_lazy as _, override
from django.views.decorators.http import require_POST

from cms import api
from cms.admin.pageadmin import PageContentAdmin as DefaultPageContentAdmin
from cms.admin.utils import ChangeListActionsMixin
from cms.api import create_page_content
from cms.extensions import extension_pool
from cms.models import PageContent, PageUrl
from cms.signals.apphook import set_restart_trigger
from cms.toolbar.utils import get_object_preview_url

from djangocms_version_locking.helpers import version_is_locked
from djangocms_version_locking.models import VersionLock
from djangocms_versioning.admin import VersioningAdminMixin
from djangocms_versioning.constants import DRAFT, PUBLISHED
from djangocms_versioning.helpers import version_list_url
from djangocms_versioning.helpers import version_is_locked, version_list_url
from djangocms_versioning.models import Version

from .compat import DJANGO_4_2
from .filters import (
AuthorFilter,
LanguageFilter,
Expand All @@ -54,7 +52,7 @@
require_POST = method_decorator(require_POST)


class PageContentAdmin(VersioningAdminMixin, DefaultPageContentAdmin):
class PageContentAdmin(ChangeListActionsMixin, VersioningAdminMixin, DefaultPageContentAdmin):
change_list_template = "admin/djangocms_pageadmin/pagecontent/change_list.html"
list_display_links = None
list_filter = (LanguageFilter, UnpublishedFilter, TemplateFilter, AuthorFilter)
Expand All @@ -80,11 +78,14 @@ def get_queryset(self, request):
# Collect locked status to handle the requirement that lock
# on a draft version dictates the unpublish permission
# on a published version
draft_version_lock_subquery = VersionLock.objects.filter(
version__content_type=OuterRef("content_type"),
version__object_id=OuterRef("object_id"),
version__state=DRAFT,
draft_version_lock_subquery = Version.objects.filter(
content_type=OuterRef("content_type"),
object_id=OuterRef("object_id"),
state=DRAFT,
locked_by__isnull=False,
).order_by("-pk")
draft_sub = Subquery(draft_version_lock_subquery.values("locked_by")[:1])
select_related_tuple = ("created_by", "locked_by")
queryset = (
super()
.get_queryset(request)
Expand All @@ -96,11 +97,9 @@ def get_queryset(self, request):
"versions",
queryset=Version.objects.annotate(
# used by locking
_draft_version_user_id=Subquery(
draft_version_lock_subquery.values("created_by")[:1]
)
_draft_version_user_id=draft_sub
)
.select_related("created_by", "versionlock")
.select_related(*select_related_tuple)
.prefetch_related("content"),
)
)
Expand Down Expand Up @@ -160,7 +159,7 @@ def get_search_results(self, request, queryset, search_term):
return returned_queryset, use_distinct

def get_version(self, obj):
return obj.versions.all()[0]
return obj.versions.all().first()

@admin.display(
description=_("state")
Expand All @@ -181,7 +180,7 @@ def url(self, obj, csv=False):
if path:
url = reverse("pages-details-by-slug", kwargs={"slug": path})
if url is not None and csv is False:
return format_html('<a class="js-page-admin-close-sideframe" href="{url}">{url}</a>', url=url)
return format_html('<a class="js-close-sideframe" href="{url}">{url}</a>', url=url)
return url

@admin.display(
Expand All @@ -201,18 +200,23 @@ def get_title(self, obj):
)
def author(self, obj):
version = self.get_version(obj)
return version.created_by
return getattr(version, "created_by", None)

@admin.display(
description=_("is locked")
)
def is_locked(self, obj):
version = self.get_version(obj)
if version.state == DRAFT and version_is_locked(version):
return render_to_string("djangocms_version_locking/admin/locked_icon.html")
return ""
if version and version.state == DRAFT and version_is_locked(version):
return mark_safe('<span class="cms-icon cms-icon-lock"></span>')
else:
return ""

def is_home(self, obj):
if obj.page.is_home:
return render_to_string("djangocms_pageadmin/admin/icons/home.html")
return ""
return mark_safe('<span class="cms-icon cms-icon-home"></span>')
else:
return ""

@admin.display(
description=_("modified date"),
Expand All @@ -238,9 +242,13 @@ def get_list_actions(self):
]

def _get_preview_link(self, obj, request, disabled=False):
return render_to_string(
"djangocms_pageadmin/admin/icons/preview.html",
{"url": get_object_preview_url(obj), "disabled": disabled, "keepsideframe": False},
return self.admin_action_button(
url=get_object_preview_url(obj),
disabled=disabled,
icon="view",
name="preview",
keepsideframe=False,
title=_("Preview"),
)

def _get_edit_link(self, obj, request, disabled=False):
Expand All @@ -249,7 +257,6 @@ def _get_edit_link(self, obj, request, disabled=False):
if version.state not in (DRAFT, PUBLISHED):
# Don't display the link if it can't be edited
return ""

if not version.check_edit_redirect.as_bool(request.user):
disabled = True

Expand All @@ -261,9 +268,14 @@ def _get_edit_link(self, obj, request, disabled=False):
)

# close sideframe as edit will always be on page and not in sideframe
return render_to_string(
"djangocms_pageadmin/admin/icons/edit.html",
{"url": url, "disabled": disabled, "get": False, "keepsideframe": False},
return self.admin_action_button(
url=url,
icon="pencil",
title=_("Edit"),
name="edit",
disabled=disabled,
action="post",
keepsideframe=False,
)

def _get_duplicate_link(self, obj, request, disabled=False):
Expand All @@ -274,9 +286,12 @@ def _get_duplicate_link(self, obj, request, disabled=False):
args=(obj.pk,),
)

return render_to_string(
"djangocms_pageadmin/admin/icons/duplicate.html",
{"url": url, "disabled": disabled},
return self.admin_action_button(
url=url,
icon="copy",
title=_("Duplicate"),
name="duplicate",
disabled=disabled,
)

def _set_home_link(self, obj, request, disabled=False):
Expand All @@ -291,9 +306,13 @@ def _set_home_link(self, obj, request, disabled=False):
args=(obj.pk,),
)

return render_to_string(
"djangocms_pageadmin/admin/icons/set_home.html",
{"url": url, "disabled": disabled, "action": True, "get": False},
return self.admin_action_button(
url=url,
icon="home",
title=_("Set as a home"),
name="set-home",
disabled=disabled,
action="post",
)

def _get_unpublish_link(self, obj, request, disabled=False):
Expand All @@ -315,30 +334,42 @@ def _get_unpublish_link(self, obj, request, disabled=False):
):
disabled = True

return render_to_string(
"djangocms_pageadmin/admin/icons/unpublish.html",
{"url": url, "disabled": disabled},
return self.admin_action_button(
url=url,
icon="unpublish",
title=_("Unpublish"),
name="unpublish",
disabled=disabled,
)

def _get_manage_versions_link(self, obj, request, disabled=False):
url = version_list_url(obj)
return render_to_string(
"djangocms_pageadmin/admin/icons/manage_versions.html",
{"url": url, "disabled": disabled, "action": False},
return self.admin_action_button(
url=url,
icon="list-ol",
title=_("Manage versions"),
name="manage-versions",
disabled=disabled,
)

def _get_basic_settings_link(self, obj, request, disabled=False):
url = reverse("admin:cms_pagecontent_change", args=(obj.pk,))
return render_to_string(
"djangocms_pageadmin/admin/icons/basic_settings.html",
{"url": url, "disabled": disabled, "action": False},
return self.admin_action_button(
url=url,
icon="settings",
title=_("Basic settings"),
name="basic-settings",
disabled=disabled,
)

def _get_advanced_settings_link(self, obj, request, disabled=False):
url = reverse("admin:cms_page_advanced", args=(obj.page_id,))
return render_to_string(
"djangocms_pageadmin/admin/icons/advanced_settings.html",
{"url": url, "disabled": disabled, "action": False},
return self.admin_action_button(
url=url,
icon="advanced-settings",
title=_("Advanced settings"),
name="advanced-settings",
disabled=disabled,
)

def _list_actions(self, request):
Expand Down Expand Up @@ -398,15 +429,17 @@ def duplicate_view(self, request, object_id):
if request.method == "POST":
form = DuplicateForm(request.POST, user=request.user, page_content=obj)
if form.is_valid():
new_page = obj.page.copy(
site=form.cleaned_data["site"],
parent_node=obj.page.node.parent,
translations=False,
permissions=False,
extensions=False,
)

new_page_content = api.create_title(
new_page_params = {
"site": form.cleaned_data["site"],
"parent_node": obj.page.node.parent,
"translations": False,
"permissions": False,
"extensions": False,
"user": request.user
}
new_page = obj.page.copy(**new_page_params)

new_page_content = create_page_content(
page=new_page,
language=obj.language,
slug=form.cleaned_data["slug"],
Expand All @@ -415,7 +448,7 @@ def duplicate_view(self, request, object_id):
template=obj.template,
created_by=request.user,
)
new_page.title_cache[obj.language] = new_page_content
new_page.page_content_cache[obj.language] = new_page_content

extension_pool.copy_extensions(
source_page=obj.page, target_page=new_page, languages=[obj.language]
Expand Down Expand Up @@ -578,18 +611,14 @@ def get_exported_queryset(self, request):
'list_max_show_all': self.list_max_show_all,
'list_editable': self.list_editable,
'model_admin': self,
'sortable_by': self.sortable_by
'sortable_by': self.sortable_by,
'search_help_text': self.search_help_text
}

if DJANGO_4_2:
changelist_kwargs.update({'search_help_text': self.search_help_text})
cl = changelist(**changelist_kwargs)

return cl.get_queryset(request)

class Media:
css = {"all": ("djangocms_pageadmin/css/actions.css",)}


admin.site.unregister(PageContent)
admin.site.register(PageContent, PageContentAdmin)
6 changes: 0 additions & 6 deletions djangocms_pageadmin/compat.py

This file was deleted.

3 changes: 2 additions & 1 deletion djangocms_pageadmin/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ def inner(self, **kwargs):
if not published_version:
return

url = published_version.get_absolute_url() if hasattr(published_version, "get_absolute_url") else None
if self.toolbar.edit_mode_active or self.toolbar.preview_mode_active:
item = ButtonList(side=self.toolbar.RIGHT)
view_published_button = ButtonWithAttributes(
_("View Published"),
url=published_version.get_absolute_url(),
url=url,
disabled=False,
extra_classes=['cms-btn', 'cms-btn-switch-save'],
html_attributes={"target": "_blank"},
Expand Down
Loading
Loading