API

Activation

class viewflow.workflow.Activation(task: Any)

Base class for flow task activations.

Activation is responsible for flow task state management and persistence. Each activation status change is restricted by a simple finite state automaton.

activate = <viewflow.fsm.base.TransitionMethod object>
activate_next = <viewflow.fsm.base.TransitionMethod object>
complete = <viewflow.fsm.base.TransitionMethod object>
classmethod create(flow_task: Any, prev_activation: Activation, token: Any, data: Any | None = None, seed: Any | None = None) Activation

Instantiate and persist a new flow task.

Args:
flow_task (Any): The flow task instance. prev_activation (Activation): The previous activation instance. token (Any): The token for the new task. data (Optional[Any]): Additional data for the new task.
Returns:
Activation: The newly created activation instance.
create_next = <viewflow.fsm.base.TransitionMethod object>
exception_guard() ContextDecorator

Perform activation action inside a transaction.

Handle and propagate exception depending on activation context state.

property flow_class: Any

Get the flow class associated with the activation.

property flow_task: Any

Get the flow task associated with the activation.

get_available_transitions(user) List[Transition]

Get the available transitions for the current status and user.

get_outgoing_transitions() List[Transition]

Get the outgoing transitions for the current status.

prepare_revived_task(task: Any) None

Hook to adjust the recreated task before revive() saves and activates it. Node types whose create() assigns extra fields (e.g. a job’s external_task_id) mirror that here.

revive = <viewflow.fsm.base.TransitionMethod object>
undo = <viewflow.fsm.base.TransitionMethod object>

Managers

class viewflow.workflow.managers.ProcessQuerySet(*args, **kwargs)

Base manager for the flow Process.

coerce_for(flow_classes)

Return subclass instances of the Task.

filter_available(flow_classes, user)

List of processes available to view for the user.

class viewflow.workflow.managers.TaskQuerySet(*args, **kwargs)

Base manager for the Task.

archive(flow_classes, user)

List of tasks finished by the user.

coerce_for(flow_classes)

Return subclass instances of the Task.

filter_available(flow_classes, user)

List of tasks available to view for the user.

inbox(flow_classes, user)

List of tasks assigned to the user.

next_user_task(process, user)

Lookup for the next task for a user execution.

Prefer assigned tasks first, if not, return first task from user queue

queue(flow_classes, user)

List of tasks permitted to assign for the user.

user_archive(user, flow_class=None)

List of tasks of the flow_class completed by the user.

user_queue(user, flow_class=None)

List of tasks of the flow_class permitted for user.

Models

class viewflow.workflow.models.AbstractProcess(*args, **kwargs)

Base class for Process data object.

property brief

Quick textual process state representation for end user.

property coerced

Return process instance of flow_class type.

class viewflow.workflow.models.Process(*args, **kwargs)

Default viewflow Process model.

exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated
class viewflow.workflow.models.AbstractTask(*args, **kwargs)

Base class for Task state objects.

In addition, you have to define at least process foreign key field:

process = models.ForeignKey(Process, on_delete=models.CASCADE)
activation()

Context manager for working with task

with task.activation() as activation:
pass
property brief

Quick textual task representation for the end user.

property coerced

Return task instance of flow_class type.

property coerced_process

Return process instance of flow_class type.

save(*args, **kwargs)

Save the current instance. Override this in a subclass if you want to control the saving process.

The ‘force_insert’ and ‘force_update’ parameters can be used to insist that the “save” must be an SQL insert or update (or equivalent for non-SQL backends), respectively. Normally, they should not be set.

class viewflow.workflow.models.Task(*args, **kwargs)

Default viewflow Task model.

exception DoesNotExist
exception MultipleObjectsReturned
exception NotUpdated

Timers

viewflow.workflow.timers.fire_due_timers()

Fire every due flow.Timer task and return the number fired.

Safe to run from several dispatchers concurrently: each task is re-checked under its flow lock, and a task locked by another dispatcher is skipped until the next run.

Flows with a custom task model that is not a proxy of viewflow.workflow.models.Task are not covered.

viewflow.workflow.timers.fire_due_start_timers(flows=None)

Start a process for every due flow.StartTimer and return the count.

By default discovers flows by importing every installed app’s flows module; pass flows to restrict dispatch to specific flow classes. Unlike fire_due_timers, there is no process row to lock before the first start – run a single dispatcher instance to avoid duplicates.

viewflow.workflow.timers.fire_due_conditions(flows=None)

Fire every armed flow.ConditionalCatch whose condition now holds.

Evaluated on the same sweep as fire_due_timers. Each task’s condition is checked under its flow lock, so a task locked by another dispatcher is skipped until the next run. Pass flows to restrict evaluation to specific flow classes.

Signals

viewflow.workflow.nodes.broadcast_signal(name, flows=None)

Fire every armed flow.SignalCatch with a matching signal name.

Returns the number of catch tasks delivered to. By default discovers flows by importing every installed app’s flows module; pass flows to restrict the broadcast. Each catch task is fired under its own flow lock, so a task locked by another worker is skipped until the next throw.

Shortcuts

class viewflow.this_object.This

Helper for building forward references to class attributes and methods.

The rationale is the ability to specify references to the class attributes and methods before they are declared. this acts similarly to self, but for class-level forward references.

resolve(instance: object, this_ref: ThisObject | ThisMethod | Any)

Resolve a forward reference on the given instance.

Args:
instance (object): The instance on which to resolve the reference. this_ref (Union[ThisObject, ThisMethod, Any]): The reference to resolve.
Returns:
Any: The resolved reference.
Raises:
AttributeError: If the reference cannot be resolved.
class viewflow.workflow.utils.Act

Shortcut to access activation data.

property process

Shortcut for lambda activation: activation.process…)

property task

Shortcut for lambda activation: activation.task…)