Я пытаюсь запустить поток представления полностью с помощью кода. Я успешно создал задачу таким образом, но мне не удалось выполнить задачу, которая следует за созданием процесса.
Я пытался использовать подход de handler, приведенный в официальной документации потока представления, но я не знаю, как это сделать правильно.
flows.py
from __future__ import unicode_literals
from viewflow import flow , Task
from viewflow.base import this, Flow
from viewflow.flow.views import CreateProcessView, UpdateProcessView, CancelProcessView, AssignTaskView, DetailProcessView
from viewflow.lock import select_for_update_lock
from .models import DeliveryProcess, Revisiones
from viewflow import frontend
from . import views
from formtools.wizard.views import SessionWizardView
@flow.flow_start_func
def create_flow(activation, campos_proceso, **kwargs):
activation.process.asignador = campos_proceso['asignador']
activation.process.ejecutor = campos_proceso['ejecutor']
activation.process.tipo_de_flujo = campos_proceso['tipo_de_flujo']
activation.process.estado_del_entregable = campos_proceso[
'estado_del_entregable']
activation.process.save()
activation.prepare()
activation.done()
return activation
@frontend.register
class Delivery_flow(Flow):
process_class = DeliveryProcess
start = flow.StartFunction(create_flow).Next(this.execution_received_handler)
execution_received_handler = (
flow.Function(
this.on_execution_recived,
task_loader=this.get_shipment_handler_task)
.Next(this.end)
)
ejecutar = (
flow.View(
UpdateProcessView,
).Assign(lambda act: act.process.ejecutor
).Next(this.end)
)
end = flow.End()
@flow.flow_func
def on_execution_recived(self, activation):
activation.process.revisor = process_fields['revisor']
activation.process.save()
activation.prepare()
activation.done()
def get_shipment_handler_task(self, flow_task, ejecutar):
return Task.objects.get(process=ejecutar.process)
views.py
from ..Flujo import flows
from datetime import datetime
from django.views import generic
from django.shortcuts import render
from .models import Revisiones, DeliveryProcess, Entregable
from viewflow.flow.views import CreateProcessView, UpdateProcessView
from viewflow.decorators import flow_start_view, flow_view
from viewflow.flow.views import StartFlowMixin, FlowViewMixin, UndoTaskView, CancelTaskView, CancelProcessView, AssignTaskView
class ReView(FlowViewMixin, generic.CreateView) :
model = Revisiones
fields = ['revisor', 'observaciones_revisor']
task_description= 'Revision'
def StartProgTask(request):#, campos_entregable):
campos_entregable = {
'nombre_entregable': 'Puente Magico',
'asignador':request.user,
'observaciones_asignador':'Este es un puente magivo',
'ejecutor':request.user,
'url_inicial':'https://www.youtube.com/watch?v=G-yNGb0Q91Y',
'email_ejecutor': 'a@a.com.co',
'tipo_de_flujo':True,
'fecha_inicio' :datetime.now(),
'fecha_final_planeada':datetime.now(),
'fecha_final_modificada':datetime.now(),
'fecha_final_real':datetime.now(),
'estado_del_entregable': True,
}
campos_proceso={
'asignador': campos_entregable['asignador'],
'ejecutor': campos_entregable['ejecutor'],
'tipo_de_flujo': campos_entregable['tipo_de_flujo'],
'estado_del_entregable': campos_entregable['estado_del_entregable'],
}
activation = flows.Delivery_flow.start.run(campos_proceso)
Entregable.objects.crear_entregable(campos_entregable)
return render(request, "Flujo/landing.html")
def Execute(request): #campos_ejecucion, request):
campos_ejecucion = {
'ejecutor':request.user,
'revisor':request.user,
# 'entregable': id_entregable, # se recibe en campos_ejecucion
'observaciones_ejecutor':'Este es un puente magico',
'url_ejecucion':'https://www.youtube.com/watch?v=G-yNGb0Q91Y',
}
campos_proceso = {
'revisor':campos_ejecucion['revisor']
}
flows.Delivery_flow.execution_received_handler.run(flows.Delivery_flow.ejecutar)
Entregable.objects.crear_entregable(campos_ejecucion)
return render(request, "Flujo/landing.html")