1

我试图完全通过代码运行视图流。我以这种方式成功创建了一个任务,但我未能执行创建该流程之后的任务。

我尝试过使用官方视图流文档中给出的 de handler 方法,但我不知道如何正确地做到这一点。

流.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)

视图.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")
4

0 回答 0