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

Feature/multi select moderation in Django admin #240

Open
wants to merge 6 commits into
base: support/django-cms-4.0.x
Choose a base branch
from

Conversation

vipulnarang95
Copy link

Description

Added feature of multi select and add to moderation workflow for Alias content admin

  • #...
  • #...

Checklist

@fsbraun
Copy link
Member

fsbraun commented Jun 19, 2024

@vipulnarang95 Shouldn't this go into moderation, which - I would assume - would add the action to any moderated model?

@vipulnarang95
Copy link
Author

@fsbraun but this implements into the model admin. How do you think we can implement this in moderation?

@fsbraun
Copy link
Member

fsbraun commented Jun 19, 2024

It could patch all registered model admins for models registered with moderation. This probably happens in cms_config.

Moderation uses monkey patching quite extensively. Since get_actions is a documented Django feature, I see no harm in adding the moderation action.

@vipulnarang95
Copy link
Author

Okay, I can look into it definitely and also I would like to add this is implemented in a similar way for pages in Pageadmin

@fsbraun
Copy link
Member

fsbraun commented Jun 19, 2024

The good thing is, it would work for all future moderated models immediately.

For pages, the challenge might be that currently there are no bulk actions to, say, delete multiple pages.

@vipulnarang95
Copy link
Author

Can you brief or give some more details on this how can this be implemented in moderation?

@fsbraun
Copy link
Member

fsbraun commented Jun 19, 2024

@vipulnarang95 I'd go into https://github.com/django-cms/djangocms-moderation/blob/master/djangocms_moderation/cms_config.py and add a handle_admin_actions method (which could be called conditionally, just like handle_moderation_request_changelist_actions and moderation_request_changelist_fields ).

You'll have to import the admin site, call site.is_registered(model_class) and if yes, get its admin class instance by calling admin_instance = site.get_model_admin(model_class).

The simplest way to add the action might be to just add it to actions:

admin_instance.actions = (admin_instance.actions or []).append(add_items_to_collection)

Obviously, this is all untested.... and will require some tests

@fsbraun fsbraun closed this Jun 19, 2024
@fsbraun fsbraun reopened this Jun 19, 2024
@vipulnarang95
Copy link
Author

@fsbraun I got this working. but can you brief on how to make it conditional?
Does it mean I should add a condition in cms_config for each component like snippet/alias? like MODERATION_ADMIN_ACTIONS=True

And then in cms_config for djangocms_moderation add:
if hasattr(cms_config, MODERATION_ADMIN_ACTIONS):
call function

This would require a config in each app. Does it makes sense? or directly enable it by default?

@fsbraun
Copy link
Member

fsbraun commented Jun 20, 2024

@vipulnarang95 Out of usability consistency, I'd have it either everywhere or nowhere. So, if conditional, then for all of djangocms-moderation. I have no clear opinion if you need to have it conditional. Is there a reason, why you want to switch the action off?

@vipulnarang95
Copy link
Author

vipulnarang95 commented Jun 20, 2024

@fsbraun I also think it should be everywhere. But you mentioned above that call handle_admin_action conditionally. That's why I was asking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants