From 1ab3ce1fabc317688182acc26e535ea104bad694 Mon Sep 17 00:00:00 2001 From: Jonathan Sundqvist Date: Fri, 11 Oct 2019 15:30:50 +0200 Subject: [PATCH] Make it possible to add collection from pagecontent admin --- djangocms_pageadmin/admin.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/djangocms_pageadmin/admin.py b/djangocms_pageadmin/admin.py index 0e7b931..861abcb 100644 --- a/djangocms_pageadmin/admin.py +++ b/djangocms_pageadmin/admin.py @@ -21,6 +21,7 @@ from cms.signals.apphook import set_restart_trigger from cms.toolbar.utils import get_object_preview_url +from djangocms_moderation.admin_actions import add_items_to_collection from djangocms_version_locking.models import VersionLock from djangocms_version_locking.helpers import version_is_locked from djangocms_versioning.admin import VersioningAdminMixin @@ -32,9 +33,16 @@ from .forms import DuplicateForm from .helpers import proxy_model +# TODO pageadmin should be usable without moderation and versioning. +# or atleast it should be usable without moderation. +using_moderation = True + require_POST = method_decorator(require_POST) +add_item_to_unpublish_collection = add_items_to_collection +add_item_to_unpublish_collection.short_description = 'Add moderation collection to unpublish' + class PageContentAdmin(VersioningAdminMixin, DefaultPageContentAdmin): change_list_template = "admin/djangocms_pageadmin/pagecontent/change_list.html" @@ -47,6 +55,9 @@ class PageContentAdmin(VersioningAdminMixin, DefaultPageContentAdmin): "state", "modified_date", ] + actions = [ + a for a in [add_item_to_unpublish_collection] if using_moderation + ] ordering = ['-versions__modified'] search_fields = ("title",) @@ -93,7 +104,6 @@ def get_version(self, obj): def state(self, obj): version = self.get_version(obj) return version.get_state_display() - state.short_description = _("state") def url(self, obj): @@ -106,7 +116,6 @@ def url(self, obj): url = reverse("pages-details-by-slug", kwargs={"slug": path}) if url is not None: return format_html('{url}', url=url) - url.short_description = _("url") def get_title(self, obj): @@ -116,13 +125,11 @@ def get_title(self, obj): lock=self.is_locked(obj), title=obj.title, ) - get_title.short_description = _("title") def author(self, obj): version = self.get_version(obj) return version.created_by - author.short_description = _("author") author.admin_order_field = "versions__created_by" @@ -140,21 +147,22 @@ def is_home(self, obj): def modified_date(self, obj): version = self.get_version(obj) return version.modified - modified_date.short_description = _("modified date") modified_date.admin_order_field = "versions__modified" def get_list_actions(self): - return [ + actions = [ self._set_home_link, self._get_preview_link, self._get_edit_link, self._get_duplicate_link, - self._get_unpublish_link, self._get_manage_versions_link, self._get_basic_settings_link, self._get_advanced_settings_link, ] + if not using_moderation: + actions.insert(4, self._get_unpublish_link) + return actions def _get_preview_link(self, obj, request, disabled=False): return render_to_string(