Open vipulnarang95 opened 2 months ago
@vipulnarang95 Shouldn't this go into moderation, which - I would assume - would add the action to any moderated model?
@fsbraun but this implements into the model admin. How do you think we can implement this in moderation?
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.
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
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.
Can you brief or give some more details on this how can this be implemented in moderation?
@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 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?
@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?
@fsbraun I also think it should be everywhere. But you mentioned above that call handle_admin_action conditionally. That's why I was asking.
Description
Added feature of multi select and add to moderation workflow for Alias content admin
...
...
Checklist