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

Added multi select feature in Snippet admin #162

Closed
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
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Changelog
Unreleased
==========

* feat: Added multiselect feature and add to moderation collection

4.1.0 (2024-05-16)
==================

Expand Down
37 changes: 37 additions & 0 deletions djangocms_snippet/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.apps import apps
from django.conf import settings
from django.contrib import admin
from django.contrib.admin import helpers
Expand Down Expand Up @@ -30,6 +31,21 @@
djangocms_versioning_enabled = False


def is_moderation_enabled():
"""
Returns True if the Snippet model is enabled for moderation.
If it is not, or djangocms_moderation is not installed, returns False.

:returns: True or False
"""
try:
moderation_config = apps.get_app_config("djangocms_moderation")
except LookupError:
return False

return Snippet in moderation_config.cms_extension.moderated_models


@admin.register(Snippet)
class SnippetAdmin(*snippet_admin_classes):
list_display = ('name',)
Expand Down Expand Up @@ -169,3 +185,24 @@ def has_delete_permission(self, request, obj=None):
get_model_permission_codename(self.model, 'add'),
)
return False

def get_actions(self, request):
"""
If djangocms-moderation is enabled, adds admin action to allow multiple snippets to be added to a moderation
collection.

:param request: Request object
:returns: dict of admin actions
"""
actions = super().get_actions(request)
if not is_moderation_enabled():
return actions

from djangocms_moderation.admin_actions import add_items_to_collection

actions["add_items_to_collection"] = (
add_items_to_collection,
"add_items_to_collection",
add_items_to_collection.short_description
)
return actions
Loading