From 0f83bbe56485672d8d5dca19597f515bef80e097 Mon Sep 17 00:00:00 2001 From: Vipul Narang <61502917+vipulnarang95@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:01:45 +0530 Subject: [PATCH] added multiselect and add to collection in admin (#273) --- CHANGELOG.rst | 4 ++++ djangocms_moderation/cms_config.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 01692029..4662f0ce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,10 @@ Changelog ========= +Unreleased +========== +* feat: Add multi select and add to moderation in admin for moderated_models + 2.2.0 (2024-05-16) ========== * Python 3.8, 3.9 support removed diff --git a/djangocms_moderation/cms_config.py b/djangocms_moderation/cms_config.py index 6dfba873..4c71d13e 100644 --- a/djangocms_moderation/cms_config.py +++ b/djangocms_moderation/cms_config.py @@ -1,8 +1,11 @@ +from django.contrib import admin from django.core.exceptions import ImproperlyConfigured from cms.app_base import CMSAppConfig, CMSAppExtension from cms.models import PageContent +from .admin_actions import add_items_to_collection + class ModerationExtension(CMSAppExtension): def __init__(self): @@ -16,6 +19,16 @@ def handle_moderation_request_changelist_actions(self, moderation_request_change def handle_moderation_request_changelist_fields(self, moderation_request_changelist_fields): self.moderation_request_changelist_fields.extend(moderation_request_changelist_fields) + def handle_admin_actions(self, moderated_models): + """ + Add items to collection to admin actions in model admin + """ + for model in moderated_models: + if admin.site.is_registered(model): + admin_instance = admin.site._registry[model] + admin_instance.actions = admin_instance.actions or [] + admin_instance.actions.append(add_items_to_collection) + def configure_app(self, cms_config): versioning_enabled = getattr(cms_config, "djangocms_versioning_enabled", False) moderated_models = getattr(cms_config, "moderated_models", []) @@ -24,6 +37,8 @@ def configure_app(self, cms_config): raise ImproperlyConfigured("Versioning needs to be enabled for Moderation") self.moderated_models.extend(moderated_models) + if moderated_models: + self.handle_admin_actions(moderated_models) if hasattr(cms_config, "moderation_request_changelist_actions"): self.handle_moderation_request_changelist_actions(cms_config.moderation_request_changelist_actions)