mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 09:33:54 +01:00
Add code to construct WorkflowMenuItem
s in snippets action menu
This commit is contained in:
parent
b03399a61a
commit
1f3bda2220
@ -284,9 +284,10 @@ class SnippetActionMenu:
|
||||
self.request = request
|
||||
self.context = kwargs
|
||||
self.context["request"] = request
|
||||
instance = self.context.get("instance")
|
||||
|
||||
if "instance" in self.context:
|
||||
self.context["model"] = self.context["instance"].__class__
|
||||
if instance:
|
||||
self.context["model"] = type(instance)
|
||||
|
||||
self.context["draftstate_enabled"] = issubclass(
|
||||
self.context["model"], DraftStateMixin
|
||||
@ -298,6 +299,32 @@ class SnippetActionMenu:
|
||||
if menu_item.is_shown(self.context)
|
||||
]
|
||||
|
||||
if instance and isinstance(instance, WorkflowMixin):
|
||||
task = instance.current_workflow_task
|
||||
current_workflow_state = instance.current_workflow_state
|
||||
is_final_task = (
|
||||
current_workflow_state and current_workflow_state.is_at_final_task
|
||||
)
|
||||
if task:
|
||||
actions = task.get_actions(instance, request.user)
|
||||
for name, label, launch_modal in actions:
|
||||
icon_name = "edit"
|
||||
if name == "approve":
|
||||
if is_final_task and not getattr(
|
||||
settings,
|
||||
"WAGTAIL_WORKFLOW_REQUIRE_REAPPROVAL_ON_EDIT",
|
||||
False,
|
||||
):
|
||||
label = _("%(label)s and Publish") % {"label": label}
|
||||
icon_name = "success"
|
||||
|
||||
item = WorkflowMenuItem(
|
||||
name, label, launch_modal, icon_name=icon_name
|
||||
)
|
||||
|
||||
if item.is_shown(self.context):
|
||||
self.menu_items.append(item)
|
||||
|
||||
self.menu_items.sort(key=lambda item: item.order)
|
||||
|
||||
for hook in hooks.get_hooks("construct_snippet_action_menu"):
|
||||
|
Loading…
Reference in New Issue
Block a user