Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _approve(context, workflow_object_identifier, username, next_state):
from django.contrib.auth.models import User
from river.models import State
workflow_object = getattr(context, "workflow_objects", {})[workflow_object_identifier]
user = User.objects.get(username=username)
workflow_object.river.my_field.approve(as_user=user, next_state=State.objects.get(label=next_state))
def workflow(context, identifier, initial_state_label):
from django.contrib.contenttypes.models import ContentType
from river.tests.models import BasicTestModel
from river.models import State
from river.models.factories import WorkflowFactory
content_type = ContentType.objects.get_for_model(BasicTestModel)
initial_state = State.objects.get(label=initial_state_label)
workflow = WorkflowFactory(initial_state=initial_state, content_type=content_type, field_name="my_field")
workflows = getattr(context, "workflows", {})
workflows[identifier] = workflow
context.workflows = workflows
def transition(context, source_state_label, destination_state_label, workflow_identifier):
from river.models import State
from river.models.factories import TransitionMetaFactory
workflow = getattr(context, "workflows", {})[workflow_identifier]
source_state = State.objects.get(label=source_state_label)
destination_state = State.objects.get(label=destination_state_label)
transition = TransitionMetaFactory.create(
workflow=workflow,
source_state=source_state,
destination_state=destination_state,
)
identifier = source_state_label + destination_state_label
transitions = getattr(context, "transitions", {})
transitions[identifier] = transition
context.transitions = transitions
def jump_workflow_object(context, workflow_object_identifier, state_label):
from river.models import State
state = State.objects.get(label=state_label)
workflow_object = getattr(context, "workflow_objects", {})[workflow_object_identifier]
workflow_object.river.my_field.jump_to(state)
def transition(context, source_state_label, destination_state_label, workflow_identifier):
from river.models import State
from river.models.factories import TransitionMetaFactory
workflow = getattr(context, "workflows", {})[workflow_identifier]
source_state = State.objects.get(label=source_state_label)
destination_state = State.objects.get(label=destination_state_label)
transition = TransitionMetaFactory.create(
workflow=workflow,
source_state=source_state,
destination_state=destination_state,
)
identifier = source_state_label + destination_state_label
transitions = getattr(context, "transitions", {})
transitions[identifier] = transition
context.transitions = transitions