Utils

Workflow

workflows.utils.set_workflow(ctype_or_obj, workflow)

Sets the workflow for passed content type or object. See the specific methods for more information.

Parameters:

workflow
The workflow which should be set to the object or model.
ctype_or_obj
The content type or the object to which the passed workflow should be set. Can be either a ContentType instance or any Django model instance.
workflows.utils.set_workflow_for_object(obj, workflow)

Sets the passed workflow to the passed object.

If the object has already the given workflow nothing happens. Otherwise the object gets the passed workflow and the state is set to the workflow’s initial state.

Parameters:

workflow
The workflow which should be set to the object. Can be a Workflow instance or a string with the workflow name.
obj
The object which gets the passed workflow.
workflows.utils.set_workflow_for_model(ctype, workflow)

Sets the passed workflow to the passed content type. If the content type has already an assigned workflow the workflow is overwritten.

The objects which had the old workflow must updated explicitely.

Parameters:

workflow
The workflow which should be set to passend content type. Must be a Workflow instance.
ctype
The content type to which the passed workflow should be assigned. Can be any Django model instance
workflows.utils.remove_workflow(ctype_or_obj)

Removes the workflow from the passed content type or object. After this function has been called the content type or object has no workflow anymore.

If ctype_or_obj is an object the workflow is removed from the object not from the belonging content type.

If ctype_or_obj is an content type the workflow is removed from the content type not from instances of the content type (if they have an own workflow)

ctype_or_obj
The content type or the object to which the passed workflow should be set. Can be either a ContentType instance or any LFC Django model instance.
workflows.utils.remove_workflow_from_object(obj)

Removes the workflow from the passed object. After this function has been called the object has no own workflow anymore (it might have one via its content type).

obj
The object from which the passed workflow should be set. Must be a Django Model instance.
workflows.utils.remove_workflow_from_model(ctype)

Removes the workflow from passed content type. After this function has been called the content type has no workflow anymore (the instances might have own ones).

ctype
The content type from which the passed workflow should be removed. Must be a ContentType instance.
workflows.utils.get_workflow(obj)

Returns the workflow for the passed object. It takes it either from the passed object or - if the object doesn’t have a workflow - from the passed object’s ContentType.

Parameters:

object
The object for which the workflow should be returend. Can be any Django model instance.
workflows.utils.get_workflow_for_object(obj)

Returns the workflow for the passed object.

Parameters:

obj
The object for which the workflow should be returned. Can be any Django model instance.
workflows.utils.get_workflow_for_model(ctype)

Returns the workflow for the passed model.

Parameters:

ctype
The content type for which the workflow should be returned. Must be a Django ContentType instance.
workflows.utils.get_objects_for_workflow(workflow)

Returns all objects which have passed workflow.

Parameters:

workflow
The workflow for which the objects are returned. Can be a Workflow instance or a string with the workflow name.

States

workflows.utils.get_state(obj)

Returns the current workflow state for the passed object.

Parameters:

obj
The object for which the workflow state should be returned. Can be any Django model instance.
workflows.utils.set_state(obj, state)

Sets the state for the passed object to the passed state and updates the permissions for the object.

Parameters:

obj
The object for which the workflow state should be set. Can be any Django model instance.
state
The state which should be set to the passed object.
workflows.utils.set_initial_state(obj)
Sets the initial state to the passed object.

Transitions

workflows.utils.get_allowed_transitions(obj, user)

Returns all allowed transitions for passed object and user. Takes the current state of the object into account.

Parameters:

obj
The object for which the transitions should be returned.
user
The user for which the transitions are allowed.
workflows.utils.do_transition(obj, transition, user)
Processes the passed transition to the passed object (if allowed).

Permissions

workflows.utils.update_permissions(obj)
Updates the permissions of the passed object according to the object’s current workflow state.

Classes

class workflows.models.Workflow(*args, **kwargs)

A workflow consists of a sequence of connected (through transitions) states. It can be assigned to a model and / or model instances. If a model instance has a workflow it takes precendence over the model’s workflow.

Attributes:

model
The model the workflow belongs to. Can be any
content
The object the workflow belongs to.
name
The unique name of the workflow.
states
The states of the workflow.
initial_state
The initial state the model / content gets if created.
get_initial_state()
Returns the initial state of the workflow. Takes the first one if no state has been defined.
get_objects()
Returns all objects which have this workflow assigned. Globally (via the object’s content type) or locally (via the object itself).
set_to(ctype_or_obj)

Sets the workflow to passed content type or object. See the specific methods for more information.

Parameters:

ctype_or_obj
The content type or the object to which the workflow should be set. Can be either a ContentType instance or any Django model instance.
set_to_model(ctype)

Sets the workflow to the passed content type. If the content type has already an assigned workflow the workflow is overwritten.

Parameters:

ctype
The content type which gets the workflow. Can be any Django model instance.
set_to_object(obj)

Sets the workflow to the passed object.

If the object has already the given workflow nothing happens. Otherwise the workflow is set to the objectthe state is set to the workflow’s initial state.

Parameters:

obj
The object which gets the workflow.
class workflows.models.State(*args, **kwargs)

A certain state within workflow.

Attributes:

name
The unique name of the state within the workflow.
workflow
The workflow to which the state belongs.
transitions
The transitions of a workflow state.
get_allowed_transitions(user)
Returns all allowed transitions for given user.
class workflows.models.Transition(*args, **kwargs)

A transition from a source to a destination state. The transition can be used from several source states.

Attributes:

name
The unique name of the transition within a workflow.
workflow
The workflow to which the transition belongs. Must be a Workflow instance.
destination
The state after a transition has been processed. Must be a State instance.
condition
The condition when the transition is available. Can be any python expression.
permission
The necessary permission to process the transition. Must be a Permission instance.
class workflows.models.StateObjectRelation(*args, **kwargs)

Stores the workflow state of an object.

Provides a way to give any object a workflow state without changing the object’s model.

Attributes:

content
The object for which the state is stored. This can be any instance of a Django model.
state
The state of content. This must be a State instance.
content
Provides a generic relation to any object through content-type/object-id fields.
class workflows.models.WorkflowPermissionRelation(*args, **kwargs)

Stores the permissions for which a workflow is responsible.

Attributes:

workflow
The workflow which is responsible for the permissions. Needs to be a Workflow instance.
permission
The permission for which the workflow is responsible. Needs to be a Permission instance.
class workflows.models.StatePermissionRelation(*args, **kwargs)

Stores granted permission for state and role.

Attributes:

state
The state for which the role has the permission. Needs to be a State instance.
permission
The permission for which the workflow is responsible. Needs to be a Permission instance.
role
The role for which the state has the permission. Needs to be a lfc Role instance.

Table Of Contents

Previous topic

Usage

This Page