这应该是可能的,但您需要考虑在“移动”步骤方面您真正想要做什么,您是想将 Page 实例实际移动到新树中的新站点还是复制当前 (及其历史)并移动该副本页面或制作副本以代替已移动的页面。
尽管如此,how to add a new Task type 上的文档是最好的起点,它会引导您完成自定义任务类型。
然而,在下面的解决方案中,我认为创建一个行为与GroupApprovalTask 完全相同的新模型(包括默认任务,用于审核)但添加一个将其链接到Site 模型的字段是最简单的.
这样,在管理 UI 中,管理员用户现在可以根据需要创建任意数量的 PublishSiteTask,每个 Site 一个(QA/Dev/Prod 等),然后每个都可以链接到不同的用户团体。区分数据库模型(具有某些字段的任务类型)和实例(在 UI 中创建的任务)以及随着工作流步骤的进行而针对每个页面修订(而不是页面)创建的实际任务实例,这一点很重要。
代码示例
models.py
from django.db import models, transaction
from wagtail.core.models import GroupApprovalTask, Page, Site
# ... other imports
class PublishSiteTask(GroupApprovalTask):
site = models.OneToOneField(Site, on_delete=models.CASCADE)
admin_form_fields = ['site'] + GroupApprovalTask.admin_form_fields
@transaction.atomic
def on_action(self, task_state, user, action_name, **kwargs):
"""Performs an action on a task state determined by the ``action_name`` string passed"""
if action_name == 'approve':
# get the page that this action is referring to via the task_state.page_revision
page = task_state.page_revision.as_page_object()
# find the new parent target at this task's site
# how this is done depends on the site/page structure
new_parent_target = self.site.root_page
# move the page to a new location
# note: this will actually move it from its current tree, you may want to make a copy first
page.move(new_parent_target)
# be sure to preserve any existing task behaviour
super().on_action(task_state, user, action_name, **kwargs)
附加链接