Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def process(workflow_object, user, action, next_state=None, god_mod=False):
proceedings = ProceedingService.get_available_proceedings(workflow_object, [workflow_object.get_state()], user=user, god_mod=god_mod)
c = proceedings.count()
if c == 0:
raise RiverException(ErrorCode.NO_AVAILABLE_NEXT_STATE_FOR_USER, "There is no available state for destination for the user.")
if c > 1:
if next_state:
proceedings = proceedings.filter(meta__transition__destination_state=next_state)
if proceedings.count() == 0:
available_states = StateService.get_available_states(workflow_object, user)
raise RiverException(ErrorCode.INVALID_NEXT_STATE_FOR_USER, "Invalid state is given(%s). Valid states is(are) %s" % (
next_state.__str__(), ','.join([ast.__str__() for ast in available_states])))
else:
raise RiverException(ErrorCode.NEXT_STATE_IS_REQUIRED,
"State must be given when there are multiple states for destination")
proceeding = proceedings[0]
proceeding.status = action
proceeding.transactioner = user
def get_objects_waiting_for_approval(content_type, user):
object_pks = []
WorkflowObjectClass = content_type.model_class()
for workflow_object in WorkflowObjectClass.objects.all():
proceedings = ProceedingService.get_available_proceedings(workflow_object, [workflow_object.get_state()], user=user)
if proceedings.count():
object_pks.append(workflow_object.pk)
return WorkflowObjectClass.objects.filter(pk__in=object_pks)
proceedings = Proceeding.objects.filter(
workflow_object=workflow_object,
meta__transition__source_state__in=source_states,
status=PENDING,
enabled=True
)
suitable_proceedings = get_proceeding(proceedings.filter(skip=False))
if user and not god_mod:
suitable_proceedings = authorize_proceedings(suitable_proceedings)
skipped_proceedings = get_proceeding(proceedings.filter(skip=True))
if skipped_proceedings:
source_state_pks = list(skipped_proceedings.values_list('meta__transition__destination_state', flat=True))
suitable_proceedings = suitable_proceedings | ProceedingService.get_available_proceedings(workflow_object,
State.objects.filter(
pk__in=source_state_pks),
user=user,
destination_state=destination_state,
god_mod=god_mod)
return suitable_proceedings
raise RiverException(ErrorCode.NEXT_STATE_IS_REQUIRED,
"State must be given when there are multiple states for destination")
proceeding = proceedings[0]
proceeding.status = action
proceeding.transactioner = user
proceeding.transaction_date = datetime.now()
if workflow_object.proceeding:
proceeding.previous = workflow_object.proceeding
proceeding.save()
return proceeding
proceeding = process(workflow_object, user, APPROVED, next_state, god_mod)
# Any other proceeding is left?
required_proceedings = ProceedingService.get_available_proceedings(workflow_object, [workflow_object.get_state()], destination_state=next_state,
god_mod=god_mod)
transition_status = False
if required_proceedings.count() == 0:
workflow_object.set_state(proceeding.meta.transition.destination_state)
transition_status = True
# Next states should be PENDING back again if there is circle.
ProceedingService.cycle_proceedings(workflow_object)
# ProceedingService.get_next_proceedings(workflow_object).update(status=PENDING)
with ProceedingSignal(workflow_object, proceeding), TransitionSignal(transition_status, workflow_object, proceeding), FinalSignal(workflow_object):
workflow_object.save()
LOGGER.debug("Workflow object %s is proceeded for next transition. Transition: %s -> %s" % (
workflow_object, workflow_object.get_state().label, workflow_object.get_state()))