Django 的工作流框架 [英] Workflow frameworks for Django

查看:26
本文介绍了Django 的工作流框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种框架来简化 Django 应用程序中相当复杂的工作流的开发.我希望能够使用该框架来自动执行状态转换、许可以及一些附加功能,例如审核日志记录和通知.

I've been looking for a framework to simplify the development of reasonably complex workflows in Django applications. I'd like to be able to use the framework to automate the state transitions, permissioning, and perhaps some extras like audit logging and notifications.

我看到过一些关于同一主题的旧信息,但在过去 2-3 年中并没有太多.我听说过的主要选择是 GoFlow(自 2/2009 以来未更新)和 django-workflow(似乎更活跃).

I've seen some older information on the same topic, but not too much in the last 2-3 years. The major choices I've heard of are GoFlow (not updated since 2/2009) and django-workflow (seems more active).

有人用过这些包吗?它们是否成熟和/或与现代 (1.3) Django 兼容?是否还有其他值得考虑的选项可能更好或更受支持?

Has anyone used these packages? Are they mature and/or compatible with modern (1.3) Django? Are there other options out there worth considering that might be better or better supported?

推荐答案

因为我是 django-fsm 和 django-viewflow 这两个可以称为工作流库"的项目的作者,所以我在这里做一些说明.

Let me give a few notes here as i'm the author of django-fsm and django-viewflow, two projects that could be called "workflow libraries".

工作流这个词本身有点被高估了.不同类型的库和软件可以称自己为工作流程",但具有不同的功能.共同点是工作流将某些流程的步骤连接成一个整体.

Workflow word itself is a bit overrated. Different kind of libraries and software could call themselves "workflow" but have varying functionality. The commonality is that a workflow connects the steps of some process into a whole.

如我所见,工作流实现方法可以分为以下几类:

As I see, workflow implementation approaches can be classified as follows:

  • 单/多用户 - 工作流库是自动执行单用户任务还是具有权限检查/任务分配选项.
  • 顺序/并行 - 顺序工作流只是一种状态机模式实现,允许在某一时刻具有单个活动状态.并行工作流允许同时执行多个活动任务,并且可能具有某种并行同步/加入功能.
  • 显式/隐式 - 无论工作流是表示为单独的外部实体,还是编入其他类,主要职责是不同的.
  • 静态/动态 - 静态工作流在 Python 代码中实现一次然后执行,动态工作流通常可以通过更改工作流数据库表的内容来配置.静态工作流通常与 Django 基础架构的其余部分更好地集成像视图、表单和模板一样,并通过类继承等通常的 python 结构支持更好的定制.动态工作流假设您拥有可以适应任何工作流运行时更改的通用接口.
  • Single/Multiple users - Whether workflow library automates single user tasks or has permission checking/task assignment options.
  • Sequential/Parallel - Sequential workflow is just a state machine pattern implementation and allows to have single active state at a moment. Parallel workflows allow to have several active tasks at once, and probably have some sort of parallel sync/join functionality.
  • Explicit/Implicit - Whether workflow is represented as a separate external entity, or is weaved into some other class, that main responsibility is different.
  • Static/Dynamic - Static workflows are implemented in python code once and then executed, dynamic workflows typically could be configuring by changing contents of workflow database tables. Static workflows are usually better integrated with the rest of the django infrastructure like views, forms and templates, and support better customization by usual python constructions like class inheritance. Dynamic workflows assume that you have generic interface that can adapt to any workflow runtime changes.

其中,前两个可以认为是渐进的差异,但其他两个是根本性的.

Of these, the first two could be considered gradual differences, but the other two are fundamental.

这里简要描述了我们现在在 django、djangopackages 和 工作流部分下的项目列表:

Here is brief description what we have nowadays in django, djangopackages and awesome-django project list under workflow section:

  • django.contrib.WizardView - 隐式、单用户、顺序、静态我们可以拥有的最简单的工作流实现.它将中间状态存储在隐藏的表单发布数据中.
  • django-flows - 显式、单用户、顺序、静态 工作流,在外部存储中保持流状态,允许用户关闭或打开另一个选项卡上的页面并继续工作.
  • django-fsm - 隐式、多用户、顺序、静态strong> 工作流 - 最紧凑和轻量级的状态机库.状态更改事件表示为模型类的 Python 方法调用.对流继承和覆盖有基本的支持.提供用于将权限与状态转换相关联的插槽.允许使用乐观锁定来防止并发状态更新.
  • django-states - 显式、多用户、顺序,静态工作流,具有单独的状态机和状态转换类.通过将转换的字符串名称传递给 make_transition 方法进行转换.提供将权限与状态转换相关联的方法.有一个简单的 REST 通用端点,用于使用 AJAX 调用更改模型状态.状态文档中没有提到机器继承支持,但类状态定义使得无需或很少修改核心库即可实现.
  • django_xworkflows - 显式、顺序、静态工作流不支持用户权限检查,状态机的分离类.将元组用于状态和转换定义,使工作流继承支持变得困难.
  • django-workflows - 显式、多用户、顺序、动态强> 工作流将状态存储在库提供的 Django 模型中.有一种方法可以将权限附加到工作流转换,基本上就是这样.
  • django.contrib.WizardView - implicit, single user, sequential, static the simplest workflow implementation we could have. It stores intermediate state in the hidden form post data.
  • django-flows - explicit, single user, sequential, static workflow, that keeps flow state in external storage, to allow user to close or open page on another tab and continue working.
  • django-fsm - implicit, multi-user, sequential, static workflow - the most compact and lightweight state machine library. State change events represented just as python methods calls of model class. Has rudimentary support for flow inheritance and overrides. Provides slots for associate permission with state transitions. Allows to use optimistic locking to prevent concurrent state updates.
  • django-states - explicit, multi-user, sequential, static workflow with separate class for state machine and state transitions. Transitions made by passing string name of transition to make_transition method. Provides way for associate permission with state transitions. Has a simple REST generic endpoint for changing model states using AJAX calls. State machine inheritance support is not mentioned in the documentation, but class state definition makes it possible with none or few core library modifications.
  • django_xworkflows - explicit, sequential, static workflow with no support for user permission checking, separated class for state machine. Uses tuples for state and transition definitions, makes workflow inheritance support hard.
  • django-workflows - explicit, multi-user, sequential, dynamic workflow storing the state in library provided django models. Has a way to attach permission to workflow transition, and basically thats all.

这些 django 状态机库都不支持并行工作流,这极大地限制了它们的应用范围.但是有两个可以:

None of these django state machine libraries have support for parallel workflows, which limits their scope of application a lot. But there are two that do:

  • django-viewflow - 显式、多用户、并行、静态 工作流,支持并行任务执行、复杂的拆分和连接语义.提供帮助器与 django 函数式和基于类的视图,以及不同的后台任务执行查询,以及各种悲观和乐观锁策略以防止并发更新.

  • django-viewflow - explicit, multi-user, parallel, static workflow, with support for parallel tasks execution, complex split and join semantic. Provides helpers to integrate with django functional and class based views, and different background task execution queries, and various pessimistic and optimistic lock strategies to prevent concurrent updates.

GoFlow 往往是显式的、多用户的、并行的、动态的 工作流,但作者为了年.

GoFlow, mentioned in question, tends to be the explicit, multi-user, parallel, dynamic workflow, but it has been forsaken by author for a years.

我看到了在 django-viewflow 之上实现动态工作流构建功能的方法.一旦完成,if 将关闭 django 世界中最后一个也是最复杂的工作流实现案例.

I see the way to implement dynamic workflow construction functionality on top of django-viewflow. As soon as it is completed, if will close the last and the most sophisticated case for workflow implementation in the django world.

希望,如果有人能读到现在,现在能更好地理解工作流术语,并且可以为他们的项目有意识地选择工作流库.

Hope, if anyone was able to read hitherto, now understands the workflow term better, and can do the conscious choice for workflow library for their project.

这篇关于Django 的工作流框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆