Skip to main content

viewflow-rest

provide restful viewflow

many of code in the project looks like django-viewflow. I want to keep the interface as same as the django viewflow.

Thanks you for all the contributors of viewflow.

The project is under ONLY USE NO PRIVATE CHANGE LICENSE, any one who change the source code (even if you just use it in intranet of just at home) should publish his code to public

Example

the flow graph can been cloned the changed from this link.

exam flow

exam flow graph

this graph like above picture can be written like the below code:

# example_project/exam/flows.py
class ExamFlow(flows.Flow):

    process_class = models.ExamProcess
    task_class = models.ExamTask

    register = nodes.Start(
        viewclass=rest_extensions.AutoCreateAPIView,
        serializer_class=serializers.RegisterExamSerializer,
    ).Next(
        this.select_term
    )

    select_term = nodes.View(
        viewclass=rest_extensions.AutoUpdateAPIView,
        fields=["term"],
    ).Next(this.take_exam)

    take_exam = nodes.View(
        viewclass=rest_extensions.AutoUpdateAPIView,
        fields=["grade"],
    ).Next(this.check_grade)

    check_grade = nodes.If(
        cond=lambda activation: activation.process.passed
    ).Then(this.end).Else(this.select_term)
    end = nodes.End()

quite simple and intuitive, right?

hire flow

source code

class HireFlow(flows.Flow):

    process_class = models.HireProcess
    task_class = models.HireTask

    start = nodes.Start(
        viewclass=rest_extensions.AutoCreateAPIView,
        serializer_class=serializers.AddCandidateSerializer,
    ).Permission(
        group=Group.objects.get_or_create(name="hr")[0]
    ).Next(
        this.split_to_3rd_and_direct_leader
    )

    split_to_3rd_and_direct_leader = nodes.Split(
    ).Always(
        this.approve
    ).Always(
        this.background_research
    )

    background_research = nodes.View(
        viewclass=rest_extensions.AutoUpdateAPIView,
        fields=["background_ok"],
    ).Next(
        this.check_background
    )

    check_background = nodes.If(
        cond=lambda activation: activation.process.background_ok
    ).Then(
        this.join_on_both_approve
    ).Else(
        this.end
            )

    join_on_both_approve = nodes.Join().Next(
        this.notify
    )

    notify = nodes.View(
        viewclass=rest_extensions.AutoUpdateAPIView,
        fields=["notified"],
    ).Next(
        this.end
    )

    approve = nodes.View(
        viewclass=rest_extensions.AutoUpdateAPIView,
        serializer_class = serializers.ApproveSerializer,
        # fields=["approved"],
    ).Permission(
        group=Group.objects.get_or_create(name="leader")[0]
    ).Next(
        this.check_if_approve
    )

    check_if_approve = nodes.If(
        cond=lambda activation: activation.process.approved
    ).Then(
        this.set_salary
    ).Else(
        this.notify
    )

    set_salary = nodes.View(
        viewclass=rest_extensions.AutoUpdateAPIView,
        fields=["salary"],
    ).Permission(
        group=Group.objects.get_or_create(name="hr")[0]
    ).Next(
        this.join_on_both_approve
    )

    end = nodes.End()
  • 中文版
  • English

Quick Start

use the example_project as a example

git clone git@github.com:ramwin/viewflow-rest.git
cd vieflow-rest/example_project/
sudo pip3 install -r ./requirements.txt
python3 manage.py migrate
python3 manage.py runserver
# visit http://localhost:8000/exam/ or http://localhost:8000/hire/ to get the api

Change Log

3.0.0 warning: break change abount the signals

The post_finish and post_start signal not use the flow_task instead of a flow_process as a sender. You should change your code from

task_started.connect(function, ProcessClass)

to

task_started.connect(function, ProcessClass.one_of_its_flow_task)

FAQ

  • How To Update the Task manually
task = models.FlowTaskModel.objects.get(id=4)
task.auto_finish(operator=User) or operator=None

The develop vedio can been seen here

  1. create project
  2. create Flow
  3. Create Start & End Node
  4. Create ViewActivation
  5. Create If Node
  6. Create Split Node
  7. Create Join Node
  8. Create Permission
  9. 0.3.0
    • one task for every flow_task
    • add serializer_class parameters for rest_extentions.views
    • add operator for every task

term

workflow

A flow contains many flow_tasks/nodes

# here exam_flow is a workflow
# it contains three flow_tasks, which were register, do, end
class ExamFlow(flows.Flow):
    register = nodes.Start(
        ...
    ).Next(this.do)
    do.nodes.View(
        ...
    ).Next(this.end)
    end = nodes.End()
exam_flow = ExamFlow()

every flow_task is a instance of Node every flow_task have a activation_class
every action_class instance will activate_next by

self.flow_task._next  // the next node instance
self.flow_task._next.activate // 

flow_task

Edge

  • src: source Node instance
  • dst: target Node instance

activations

  • Attribute
    • flow_class
    • flow_task: Node Instance defined in the flows.py
    • task: Current Task

Nodes

  • Function
    • _incoming: Edge Instance list
    • _outgoing: Edge Instance list
  1. models

  2. Views

  3. Flow

  4. rest_extensions

Metadata

Release files for viewflow-rest 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for viewflow-rest 3.0.0
File Size Uploaded
viewflow-rest-3.0.0.tar.gz 13.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for viewflow-rest 3.0.0
File Interpreter ABI Platform
viewflow_rest-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 29.8 kB

Release files / viewflow-rest-3.0.0.tar.gz

Download URL viewflow-rest-3.0.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f0a5e2f6785e644e0ce832989cccb86df53a0dac0750eb6fb7639d29d5493b1b
BLAKE2b-256 checksum
How to use checksums
87efe6679d34b7da6ba0db499c6b8a4725305eb9ff7513ecb823b717129c7e95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release files / viewflow_rest-3.0.0-py3-none-any.whl

Download URL viewflow_rest-3.0.0-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aec9d0819e2c7a47bc7db744d946921b7909c90f4eba25daab2b46e80a5c54ce
BLAKE2b-256 checksum
How to use checksums
e2939ffc97e897f9071ddc00ed0229a718ffa6e1199f94a26890e126bf5da327
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.5

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.1.0

1 release file

2.0.1

1 release file

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page