django-cms / djangocms-alias

Other
8 stars 23 forks source link

Feature/multi select moderation in Django admin #240

Open vipulnarang95 opened 2 months ago

vipulnarang95 commented 2 months ago

Description

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

Checklist

fsbraun commented 2 months ago

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

vipulnarang95 commented 2 months ago

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

fsbraun commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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

fsbraun commented 2 months ago

@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

vipulnarang95 commented 2 months ago

@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 commented 2 months ago

@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 commented 2 months ago

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