Exemplo n.º 1
0
class DocumentUploadFlow(Flow):
    process_class = DocumentUploadProcess

    start = (
        flow.Start(
            views.start_upload_workflow
            #CreateProcessView,
            #fields=["text"]
        ).Permission(
            #auto_create=True
            'munshai.add_helloworldprocess'
            #'munshai.can_start_helloworldprocess',
            #'munshai.can_view_helloworldprocess'
        ).Next(this.approve))

    approve = (
        flow.View(UpdateProcessView, fields=["approved", "upload"]).Permission(
            #auto_create=True
            'munshai.can_approve_helloworldprocess',
            #'munshai.can_approve_helloworldprocess'
            #'munshai.view_helloworldrocess'
        ).Next(this.check_approve))

    check_approve = (
        flow.If(lambda activation: activation.process.approved).Then(
            this.send).Else(this.end))

    send = (flow.Handler(this.send_hello_world_request).Next(this.end))

    end = flow.End()

    def send_hello_world_request(self, activation):
        print(activation.process.text)
        print(activation.process.upload)
Exemplo n.º 2
0
class JoinTestFlow(Flow):
    start = flow.StartFunction().Next(this.split)
    split = flow.Split().Next(this.task1).Next(this.task2)
    task1 = flow.Function(func, task_loader=lambda flow_task, task: task).Next(this.join)
    task2 = flow.Function(func, task_loader=lambda flow_task, task: task).Next(this.join)
    join = flow.Join().Next(this.end)
    end = flow.End()
Exemplo n.º 3
0
class OrderFlow(Flow):
    """
    Order fulfilment

    Verify customers and send ordered items.
    """
    process_class = models.OrderProcess
    lock_impl = lock.select_for_update_lock

    start = flow.Start(
        CreateProcessView,
        form_class=forms.OrderForm
    ).Next(this.verify_customer)

    verify_customer = flow.Subprocess(
        CustomerVerificationFlow.start
    ).Next(this.check_verify)

    check_verify = flow.If(
        cond=lambda act: models.CustomerVerificationProcess.objects.get(
            parent_task__status=STATUS.DONE,
            parent_task__process=act.process
        ).trusted
    ).Then(this.prepare_items).Else(this.end)

    prepare_items = flow.NSubprocess(
        OrderItemFlow.start,
        lambda p: p.orderitem_set.all()
    ).Next(this.end)

    end = flow.End()
Exemplo n.º 4
0
class BloodTestFlow(Flow):
    process_class = models.BloodTestProcess

    first_sample = flow.Start(views.FirstBloodSampleView).Next(
        this.biochemical_analysis)

    second_sample = flow.Start(views.second_blood_sample).Next(
        this.biochemical_analysis)

    biochemical_analysis = flow.View(views.biochemical_data).Next(
        this.split_analysis)

    split_analysis = (flow.Split().Next(
        this.hormone_tests,
        cond=lambda act: act.process.hormone_test_required).Next(
            this.tumor_markers_test,
            cond=lambda act: act.process.tumor_test_required).Next(
                this.join_analysis))

    hormone_tests = flow.View(views.HormoneTestFormView).Next(
        this.join_analysis)

    tumor_markers_test = flow.View(
        views.GenericTestFormView,
        model=models.TumorMarkers,
        fields=[
            'alpha_fetoprotein', 'beta_gonadotropin', 'ca19', 'cea', 'pap',
            'pas'
        ],
        task_description='Tumor Markers Test').Next(this.join_analysis)

    join_analysis = flow.Join().Next(this.end)

    end = flow.End()
Exemplo n.º 5
0
class HelloWorldFlow(Flow):
    process_class = HelloWorldProcess
    """
    Implementação do evento de inicialização do processo
    """
    start = (flow.Start(CreateProcessView,
                        fields=["text"]).Permission(auto_create=True).Next(
                            this.approve))
    """
    Implementação da atividade de aprovação da instância de processo
    """
    approve = (flow.View(UpdateProcessView, fields=[
        "approved"
    ]).Permission(auto_create=True).Next(this.check_approve))
    """
    implementação de elemento de decisão exclusiva
    """
    check_approve = (
        flow.If(lambda activation: activation.process.approved).Then(
            this.send).Else(this.end))

    send = (flow.Handler(this.send_hello_world_request).Next(this.end))

    end = flow.End()

    def send_hello_world_request(self, activation):
        print(activation.process.text)
Exemplo n.º 6
0
class HelloWorldFlow(Flow):
    """
    Hello world

    This process demonstrates hello world approval request flow.
    """
    process_cls = HelloWorldProcess
    lock_impl = lock.select_for_update_lock

    summary_template = "'{{ process.text }}' message to the world"

    start = flow.Start(StartProcessView,
                       fields=['text']).Permission(auto_create=True).Next(
                           this.approve)

    approve = flow.View(
        ProcessView,
        fields=['approved'],
        task_description="Message approvement required",
        task_result_summary=
        "Messsage was {{ process.approved|yesno:'Approved,Rejected' }}"
    ).Permission(auto_create=True).Next(this.check_approve)

    check_approve = flow.If(cond=lambda p: p.approved).OnTrue(
        this.send).OnFalse(this.end)

    send = celery.Job(send_hello_world_request).Next(this.end)

    end = flow.End()
Exemplo n.º 7
0
class StartUndoFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.func_task)
    func_task = flow.Function(function_task).Next(this.end)
    end = flow.End()

    def start_undo(self, activation):
        self.handler_called = True
Exemplo n.º 8
0
class ManageOrderFlow(Flow):
    process_class = ManageOrderProcess
    lock_impl = select_for_update_lock

    chef_recieve_order = (rf.Start(
        v.CreateProcessView,
        fields=["menuitem"]).Permission(auto_create=True).Next(this.chef_cook))

    chef_cook = (f.View(UpdateProcessView,
                        fields=["cook"]).Permission(auto_create=True).Next(
                            this.chef_serve))

    chef_serve = (f.View(UpdateProcessView,
                         fields=["serve"]).Permission(auto_create=True).Next(
                             this.Is_return_item))

    Is_return_item = (f.View(UpdateProcessView, fields=[
        "returnitem"
    ]).Permission(auto_create=True).Next(this.check_return))

    check_return = (
        f.If(lambda activation: activation.process.returnitem).Then(
            this.chef_serve).Else(this.chef_pay))

    chef_pay = (f.View(UpdateProcessView,
                       fields=["pay"]).Permission(auto_create=True).Next(
                           this.end_flow))

    end_flow = f.End()
Exemplo n.º 9
0
class SavableFlow(Flow):
    process_class = SavableProcess
    start = flow.Start(CreateProcessView, fields=[]).Next(this.savable_task)
    savable_task = flow.View(SavableProcessView) \
        .Assign(username='******') \
        .Next(this.end)
    end = flow.End()
Exemplo n.º 10
0
class CreateWorksFlow(Flow):
    """ Create works for the items listed in the linked spreadsheet
    """
    process_class = ImplicitPlaceProcess
    summary_template = "Create works for {{ process.place_name }}"
    start_from_ui = True

    start = (flow.Start(views.StartPlaceWorkflowView).Permission(
        'indigo_api.review_work').Next(this.instructions))

    # wait for human to do the work and then move the task into the next state
    instructions = (flow.View(
        views.HumanInteractionView,
        task_title="Create works for items in a spreadsheet",
        task_description=format_html(
            '<a href="/works/new">Create a work</a> for each item listed in the linked spreadsheet.'
        ),
        task_result_summary="{{ flow_task.task_description }}",
    ).Permission('indigo_api.add_work').Next(this.review))

    review = (flow.View(
        views.ReviewTaskView,
        fields=['approved'],
        task_title="Review and approve listed works",
        task_description=
        "Review the created works in the spreadsheet. The task is done if all the works have been created.",
        task_result_summary="{{ flow_task.task_description }}",
    ).Permission('indigo_api.review_work').Next(this.check_approved))

    check_approved = (flow.If(lambda a: a.process.approved).Then(
        this.end).Else(this.instructions))

    end = flow.End()
Exemplo n.º 11
0
class ModerateAccidentFlow(Flow):
    process_class = models.AccidentPendingModeration

    start = flow.StartFunction(this.start_flow).Next(this.approve)

    approve = flow.View(UpdateProcessView, fields=[
        'approved'
    ]).Permission('icw.moderate_accident').Next(this.check_approve)

    check_approve = flow.If(
        lambda activation: activation.process.approved).Then(
            this.approved).Else(this.end)

    end = flow.End()

    def start_flow(self, activation: Activation):
        activation.prepare()
        activation.done()
        return activation

    @flow.Handler
    def approved(self, activation):
        pass

    class Meta:
        view_permission_name = 'icw.moderate_accident'
Exemplo n.º 12
0
class CreatePointInTimeFlow(Flow):
    """ Create a new point in time for a work
    """
    process_class = CreatePointInTimeProcess
    summary_template = "Create a new point in time for {{ process.work.frbr_uri }} at {{ process.date|date:'Y-m-d' }} in {{ process.language.language.name_en }}"
    start_from_ui = False

    start = (flow.Start(views.StartCreatePointInTimeView).Permission(
        'indigo_api.add_amendment').Next(this.instructions))

    # wait for human to do the work and then move the task into the next state
    instructions = (flow.View(
        views.HumanInteractionView,
        task_title="Consolidate or import a point in time version of the work",
        task_description=format_html(
            'Visit the work\'s point in time page. Consolidate or import a version at the specified date, in the specified language.'
        ),
        task_result_summary="{{ flow_task.task_description }}",
    ).Permission('indigo_api.add_document').Next(this.review))

    review = (flow.View(
        views.ReviewTaskView,
        fields=['approved'],
        task_title="Review and approve the created point in time",
        task_description=
        "Review the document for the specific point in time and language. The task is done if the work has been correctly consolidated.",
        task_result_summary="{{ flow_task.task_description }}",
    ).Permission('indigo_api.review_document').Next(this.check_approved))

    check_approved = (flow.If(lambda a: a.process.approved).Then(
        this.end).Else(this.instructions))

    end = flow.End()
Exemplo n.º 13
0
class ListWorksFlow(Flow):
    """ Research works for a place and list them in the linked spreadsheet
    """
    process_class = ImplicitPlaceProcess
    summary_template = "List works for {{ process.place_name }}"
    start_from_ui = True

    start = (flow.Start(views.StartPlaceWorkflowView).Permission(
        'indigo_api.review_work').Next(this.instructions))

    # wait for human to do the work and then move the task into the next state
    instructions = (flow.View(
        views.HumanInteractionView,
        task_title="List work details in a spreadsheet",
        task_description=
        "List the short title, publication date, gazette name and number in the linked spreadsheet.",
        task_result_summary="{{ flow_task.task_description }}",
    ).Permission('indigo_api.add_work').Next(this.review))

    review = (flow.View(
        views.ReviewTaskView,
        fields=['approved'],
        task_title="Review and approve listed works",
        task_description=
        "Review the listed works in the spreadsheet. The task is done if the list is complete and has all required details for all works.",
        task_result_summary="{{ flow_task.task_description }}",
    ).Permission('indigo_api.review_work').Next(this.check_approved))

    check_approved = (flow.If(lambda a: a.process.approved).Then(
        this.end).Else(this.instructions))

    end = flow.End()
Exemplo n.º 14
0
class ApplicationFlow(Flow):
    process_class = ApplicationProcess
    process_title = 'ApplicationFlow'
    process_description = 'Process used to apply for a grant.'

    start = flow.Start(ApplicationView).Next(this.legal_approval)

    legal_approval = flow.View(UpdateProcessView,
                               fields=['legal_approved'
                                       ]).Next(this.finance_approval)

    finance_approval = flow.View(UpdateProcessView,
                                 fields=['finance_approved'
                                         ]).Next(this.notify_applicant)

    notify_applicant = flow.Handler(this.send_applicant_notification).Next(
        this.end)

    end = flow.End()

    def send_applicant_notification(self, activation):
        subject = 'Application rejected.'
        message = 'Sorry but your application has been rejected.'

        approved = all([
            activation.process.legal_approved,
            activation.process.finance_approved
        ])

        if approved:
            subject = 'Application approved.'
            message = 'Congratulations, your application has been approved.'

        logger.info(subject, message)
Exemplo n.º 15
0
class OrderFlow(Flow):
    """
    Acceess List 

    Configure Access List in Multi Vendor.
    """
    process_cls = models.OrderProcess
    lock_impl = lock.select_for_update_lock


    start = flow.Start(views.StartView).Next(this.config)


    config = flow.View(views.AclConfigView,
            task_description="ACl 설정 입력",
            ).Next(this.verify_config)

    verify_config = flow.View(
        views.CustomerVerificationView,
        task_description="설정 정보 확인",
    ).Next(this.check_verify)

    check_verify = flow.If(cond=lambda p: p.is_true()) \
          .OnTrue(this.end) \
          .OnFalse(this.rollback)


    rollback = flow.View(
        views.RollbackView,
        task_description=" 원상복구 "
    ).Next(this.end)

    end = flow.End()
Exemplo n.º 16
0
class IfTestFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.if_task)
    if_task = flow.If(cond=lambda process: True).OnTrue(this.on_true).OnFalse(
        this.on_false)
    on_true = flow.Handler(handler).Next(this.end)
    on_false = flow.Handler(handler).Next(this.end)
    end = flow.End()
Exemplo n.º 17
0
class HelloWorldFlow(Flow):
    """
    Hello world

    This process demonstrates hello world approval request flow.
    """
    process_cls = HelloWorldProcess
    lock_impl = lock.select_for_update_lock

    start = flow.Start(flow_views.StartProcessView, fields=['text']) \
        .Permission(auto_create=True) \
        .Next(this.approve)

    approve = flow.View(flow_views.ProcessView, fields=['approved']) \
        .Permission(auto_create=True) \
        .Next(this.check_approve)

    check_approve = flow.If(cond=lambda p: p.approved) \
        .OnTrue(this.send) \
        .OnFalse(this.end)

    send = celery.Job(send_hello_world_request) \
        .Next(this.end)

    end = flow.End()
Exemplo n.º 18
0
class SwitchTestFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.switch)
    switch = flow.Switch().Case(this.task1,
                                cond=lambda process: True).Default(this.task2)
    task1 = flow.Handler(handler).Next(this.end)
    task2 = flow.Handler(handler).Next(this.end)
    end = flow.End()
Exemplo n.º 19
0
class JoinTestFlow(Flow):
    start = flow.StartFunction().Next(this.split)
    split = flow.Split().Next(this.task1).Next(this.task2)
    task1 = flow.Function(func).Next(this.join)
    task2 = flow.Function(func).Next(this.join)
    join = flow.Join().Next(this.end)
    end = flow.End()
Exemplo n.º 20
0
class HelloWorldFlow(Flow):
    """
    Hello world

    This process demonstrates hello world approval request flow.
    """
    process_class = HelloWorldProcess
    lock_impl = lock.CacheLock()

    summary_template = "'{{ process.text }}' message to the world"

    start = (flow.Start(flow_views.CreateProcessView,
                        fields=['text']).Permission(auto_create=True).Next(
                            this.approve))

    approve = (flow.View(
        flow_views.UpdateProcessView,
        fields=['approved'],
        task_description="Message approvement required",
        task_result_summary=
        "Messsage was {{ process.approved|yesno:'Approved,Rejected' }}").
               Permission(auto_create=True).Next(this.check_approve))

    check_approve = (flow.If(cond=lambda act: act.process.approved).Then(
        this.send).Else(this.end))

    send = celery.Job(send_hello_world_request).Next(this.end)

    end = flow.End()
Exemplo n.º 21
0
class HelloWorldFlow(Flow):
    """
    Hello world process

    This process demonstrates hello world approval request flow.

    1. User with *helloworld.can_start_process* permission creates hello world request
    2. Manager, who have *helloworld.can_approve_request* approves it
    3. And if request was approved, background celery job sends it to the world
    4. Elsewhere, request became cancelled
    """
    process_cls = HelloWorldProcess
    lock_impl = select_for_update_lock

    start = flow.Start(StartView, fields=['text']) \
        .Permission(auto_create=True) \
        .Next(this.approve)

    approve = flow.View(ProcessView, fields=['approved']) \
        .Permission(auto_create=True) \
        .Next(this.send)

    check_approve = flow.If(cond=lambda p: p.approved) \
        .OnTrue(this.send) \
        .OnFalse(this.end)

    send = flow.Job(send_hello_world_request) \
        .Next(this.end)

    end = flow.End()
Exemplo n.º 22
0
class DeliveryFlow(Flow):
    """
    Parcel Delivery
    """
    process_class = models.DeliveryProcess

    start = flow.Start(
        CreateProcessView,
        fields=["planet", "description"],
        task_title="New Parcel").Permission('parcel.add_parcel').Next(this.end)

    # approve = flow.View(
    #     UpdateProcessView, form_class=forms.ApproveForm,
    #     task_title="Approve").Assign(lambda act: User.objects.filter(
    #         is_superuser=True).order_by('?')[0]).Next(this.check_approve)

    # check_approve = flow.If(cond=lambda act: act.process.approved).Then(
    #     this.delivery).Else(this.end)

    # delivery = flow.View(
    #     UpdateProcessView,
    #     form_class=forms.DropStatusForm).Permission(auto_create=True).Next(
    #         this.report)

    # report = flow.View(
    #     UpdateProcessView,
    #     fields=["delivery_report"]).Assign(this.delivery.owner).Next(this.end)

    end = flow.End()
Exemplo n.º 23
0
class HelloWorldFlow(Flow):
    process_class = HelloWorldProcess

    start = (
        flow.Start(
            CreateProcessView,
            fields=["text"]
        ).Permission(
            auto_create=True
        ).Next(this.approve)
    )

    approve = (
        flow.View(
            UpdateProcessView,
            fields=["approved"]
        ).Permission(
            auto_create=True
        ).Next(this.check_approve)
    )

    check_approve = (
        flow.If(lambda activation: activation.process.approved)
        .Then(this.send)
        .Else(this.end)
    )

    send = (
        celery.Job(
            send_hello_world_request
        ).Next(this.end)
    )

    end = flow.End()
Exemplo n.º 24
0
class QingJiaFlow(Flow):
    process_class = QingJiaProcess

    start = (flow.Start(
        CreateProcessView,
        fields=["text", "days", "demo"],
    ).Permission(auto_create=True).Next(this.submit))

    submit = (flow.View(UpdateProcessView, fields=[
        "submit", "submit_note"
    ]).Permission(auto_create=True).Next(this.approve))

    approve = (flow.View(UpdateProcessView, fields=[
        "approved"
    ]).Permission(auto_create=True).Next(this.check_approve))

    check_approve = (
        flow.If(lambda activation: activation.process.approved).Then(
            this.send).Else(this.end))

    send = (flow.Handler(this.send_qing_jia_request).Next(this.end))

    end = flow.End()

    def send_qing_jia_request(self, activation):
        print(activation.process.text)
Exemplo n.º 25
0
class ListViewTestFlow(Flow):
    start1 = flow.StartFunction().Next(this.test_task)
    start2 = flow.Start(lambda request: None).Permission(
        'auth.start_flow_perm').Next(this.test_task)
    start3 = flow.Start(lambda request: None).Next(this.test_task)
    test_task = flow.View(lambda request: None).Next(this.end)
    end = flow.End()
Exemplo n.º 26
0
class BrokenGateFlow(Flow):
    process_cls = BrokenGateProcess

    start = flow.StartFunction(create_test_flow).Next(this.gate)
    gate = flow.If(lambda process: process.test()).OnTrue(this.end).OnFalse(
        this.end)
    end = flow.End()
Exemplo n.º 27
0
class OrderItemFlow(Flow):
    process_class = models.OrderItemProcess
    lock_impl = lock.select_for_update_lock

    start = flow.StartSubprocess(this.start_func).Next(this.reserve_item)

    reserve_item = flow.View(
        views.OrderReservationView,
        task_description="Is item reservation succeed?",
        task_result_summary="Customer is {{ process.trusted|yesno:'Trusted,Unreliable' }}"
    ).Assign(
        lambda act: act.process.parent_task.process.created_by
    ).Next(this.check_reservation)

    check_reservation = flow.If(
        cond=lambda act: act.process.item.reserved
    ).Then(this.pack_item).Else(this.end)

    pack_item = flow.View(
        UpdateProcessView,
        task_description="Pack the item",
        task_result_summary="Item packed"
    ).Assign(
        lambda act: act.process.parent_task.process.created_by
    ).Next(this.end)

    end = flow.End()

    @method_decorator(flow.flow_start_func)
    def start_func(self, activation, parent_task, item):
        activation.prepare(parent_task)
        activation.process.item = item
        activation.done()
        return activation
Exemplo n.º 28
0
class IgnorableSignalFlow(Flow):
    start = (
        flow.StartSignal(
            start_ignorable_test_signal, create_flow)
        .Next(this.signal_task)
    )

    signal_task = (
        flow.Signal(
            ignorable_test_signal, this.on_test_signal,
            task_loader=this.get_signal_task,
            allow_skip=True)
        .Next(this.end)
    )

    end = flow.End()

    def get_signal_task(self, flow_task, **kwargs):
        if kwargs['ignore_me']:
            return None
        return kwargs['process'].get_task(IgnorableSignalFlow.signal_task)

    @method_decorator(flow.flow_signal)
    def on_test_signal(self, activation, **signal_kwargs):
        activation.prepare()
        activation.done()
Exemplo n.º 29
0
class DynamicSplitFlow(Flow):
    """
    Dynamic split

    Depends on initial decision, several instances on make_decision task would be instantiated
    """
    process_class = models.DynamicSplitProcess

    summary_template = """
    Decision on: {{ process.question }}<br/>
    {{ process.decision_set.count }}  of {{ process.split_count }} completed
    """

    start = (flow.Start(
        CreateProcessView,
        fields=['question', 'split_count'],
        task_result_summary="Asks for {{ process.split_count }} decisions").
             Permission(auto_create=True).Next(this.spit_on_decision))

    spit_on_decision = (DynamicSplit(lambda p: p.split_count).Next(
        this.make_decision))

    make_decision = (flow.View(views.DecisionView,
                               task_description="Decision required").Next(
                                   this.join_on_decision))

    join_on_decision = flow.Join().Next(this.end)

    end = flow.End()
Exemplo n.º 30
0
class BaseFlow(Flow):
    start = flow.StartFunction().Next(this.end)
    handle = flow.Handler(this.handler_execute)
    end = flow.End()

    def handler_execute(self, activation):
        raise NotImplementedError