Skip to content

Commit

Permalink
added multiselect and add to collection in admin (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
vipulnarang95 authored Jul 2, 2024
1 parent e2e8ac2 commit 0f83bbe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions djangocms_moderation/cms_config.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -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", [])
Expand All @@ -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)
Expand Down

0 comments on commit 0f83bbe

Please sign in to comment.