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()
class ShipmentFlow(Flow): """ Parcel Shipment This process demonstrates hello world approval request flow. """ process_cls = models.ShipmentProcess task_cls = models.ShipmentTask lock_impl = lock.select_for_update_lock start = flow.Start(views.register_shipment) \ .Permission('parcel.add_parcel') \ .Next(this.approve) approve = flow.View(views.approve_shipment) \ .Assign(lambda p: get_user_model().objects.get(email='*****@*****.**')) \ .Next(this.check_approve) check_approve = flow.If(cond=lambda p: p.approved) \ .OnTrue(this.deliver) \ .OnFalse(this.end) deliver = flow.View(views.deliver, assign_view=views.deliver_assign) \ .Permission('parcel.land_on_planet', obj=lambda p: p.parcel.planet) \ .Next(this.report) report = flow.View(views.deliver_report) \ .Assign(this.deliver.owner) \ .Next(this.end) end = flow.End()
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()
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'
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()
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)
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()
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()
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()
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)
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()
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()
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()
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
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)
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()
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()
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()
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()
class ShipmentFlow(Flow): process_cls = ShipmentProcess task_cls = ShipmentTask lock_impl = select_for_update_lock start = flow.Start(views.StartView) \ .Permission('shipment.can_start_request') \ .Next(this.split_clerk_warehouse) # clerk split_clerk_warehouse = flow.Split() \ .Next(this.shipment_type) \ .Next(this.package_goods) shipment_type = flow.View(views.ShipmentView, fields=["carrier"]) \ .Next(this.delivery_mode) \ .Assign(lambda p: p.created_by) delivery_mode = flow.If(cond=lambda p: p.is_normal_post()) \ .OnTrue(this.check_insurance) \ .OnFalse(this.request_quotes) request_quotes = flow.View(views.ShipmentView, fields=["carrier_quote"]) \ .Next(this.join_clerk_warehouse) \ .Assign(lambda p: p.created_by) check_insurance = flow.View(views.ShipmentView, fields=["need_insurance"]) \ .Next('split_on_insurance') \ .Assign(lambda p: p.created_by) split_on_insurance = flow.Split() \ .Next(this.take_extra_insurance, cond=lambda p: p.need_extra_insurance()) \ .Always(this.fill_post_label) fill_post_label = flow.View(views.ShipmentView, fields=["post_label"]) \ .Next(this.join_on_insurance) \ .Assign(lambda p: p.created_by) join_on_insurance = flow.Join() \ .Next(this.join_clerk_warehouse) # Logistic manager take_extra_insurance = flow.View(views.InsuranceView) \ .Next(this.join_on_insurance) \ .Permission('shipment.can_take_extra_insurance') # Warehouse worker package_goods = flow.View(ProcessView.as_view()) \ .Next(this.join_clerk_warehouse) \ .Permission('shipment.can_package_goods') join_clerk_warehouse = flow.Join() \ .Next(this.move_package) move_package = flow.View(ProcessView.as_view()) \ .Next(this.end) \ .Assign(this.package_goods.owner) end = flow.End()
def test_if_activation_activate(self): flow_task_mock = mock.Mock(spec=flow.If(lambda act: True)) flow_task_mock._outgoing = mock.Mock(return_value=[]) prev_activation_mock = mock.Mock(spec=activation.StartActivation()) act = gates.IfActivation.activate(flow_task_mock, prev_activation_mock, Token('start')) act.task.save.assert_has_calls(())
class BuyMatFlow(Flow): process_class = BuyMaterialProcess task_class = BuyMaterialTask lock_impl = select_for_update_lock chef_start_order = (f.Start(views.StartView, ).Permission( auto_create=True).Next(this.manager_approve_order)) manager_approve_order = (f.View(UpdateProcessView, fields=[ "approved" ]).Permission(auto_create=True).Next(this.check_order)) check_order = (f.If(lambda activation: activation.process.approved).Then( this.sup_deliverly).Else(this.chef_fix_order)) chef_fix_order = (f.View(views.FixView, ).Permission( auto_create=True).Next(this.manager_approve_order)) sup_deliverly = (f.View(views.DateView, fields=[ "datesent" ]).Permission(auto_create=True).Next(this.manager_check_deliverly)) manager_check_deliverly = (f.View(UpdateProcessView, fields=[ "approved" ]).Permission(auto_create=True).Next(this.check_deliverly)) check_deliverly = ( f.If(lambda activation: activation.process.approved).Then( this.end_flow).Else(this.manager_complain)) manager_complain = (f.View(UpdateProcessView, fields=[ "text" ]).Permission(auto_create=True).Next(this.supplier_return_order)) supplier_return_order = (f.View(views.DateView, fields=[ "datereturn" ]).Permission(auto_create=True).Next(this.manager_reorder)) manager_reorder = (f.View(UpdateProcessView, fields=[ "approved" ]).Permission(auto_create=True).Next(this.check_reorder)) check_reorder = (f.If(lambda activation: activation.process.approved).Then( this.sup_deliverly).Else(this.end_flow)) end_flow = f.End()
class TestFlow(Flow): process_class = SavableProcess start = flow.Start(CreateProcessView, fields=[]).Next(this.savable_task) savable_task = flow.View(SavableProcessView) \ .Assign(username='******') \ .Next(this.if_task) if_task = flow.If(1 == 1).Then(this.switch_task).Else(this.end) switch_task = flow.Switch().Case(this.end, cond=(1 == 1)) end = flow.End()
class HelloWorldFlow(Flow): """ Hello world This process demonstrates hello world approval request flow. """ process_class = HelloWorldProcess process_title = _('Hello world') process_description = _('This process demonstrates hello world approval request flow.') lock_impl = lock.select_for_update_lock summary_template = _("'{{ process.text }}' message to the world") start = ( flow.Start( flow_views.CreateProcessView, fields=['text'], task_title=_('New message')) .Permission(auto_create=True) .Next(this.approve) ) approve = ( flow.View( flow_views.UpdateProcessView, fields=['approved'], task_title=_('Approve'), 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, task_title=_('Approvement check'), ) .Then(this.send) .Else(this.end) ) send = ( flow.Handler( this.send_hello_world_request, task_title=_('Send message'), ) .Next(this.end) ) end = flow.End( task_title=_('End'), ) def send_hello_world_request(self, activation): with open(os.devnull, "w") as world: world.write(activation.process.text)
class FailedJobFlow(Flow): """ Test that failed job gate stored task in error state """ lock_impl = lock.cache_lock start = flow.Start().Next(this.job) job = celery.Job(tasks.dummy_job).Next(this.iff) iff = flow.If(lambda p: 2 / (1 - 1)).OnTrue(this.end).OnFalse(this.end) end = flow.End()
class HelloWorldFlow(Flow): process_class = HelloWorldProcess flow_id = 2 start = (Start(StartView).Permission(auto_create=True).Next( this.check_start)) check_start = ( flow.If(lambda activation: activation.process.is_terminate).Then( this.end).Else(this.approve)) # approve = ( # flow.View( # UpdateProcessView, # fields=["approved"] # ).Assign(owner=User.objects.filter(username__in=['porter']).first()).Permission(auto_create=True).Next(this.check_approve) # ) approve = (Approval( view_or_class=ApprovalView, wait_all=False, task_title='审批').Assign(owner_list=this.get_approve_user).Permission( auto_create=True).Next(this.check_approve)) check_approve = ( flow.If(lambda activation: activation.process.approved).Then( this.send).Else(this.approve2)) send = (flow.Handler(this.send_hello_world_request).Next(this.end)) approve2 = (Approval( view_or_class=ApprovalView, task_title='审批2').Assign(owner_list=User.objects.filter( username__in=['porter', 'admin', 'wjc']).all()).Permission( auto_create=True).Next(this.end)) end = flow.End() def send_hello_world_request(self, activation): print(activation.process.text) def get_approve_user(self, activation): return User.objects.filter( username__in=['porter', 'admin', 'wjc']).all()
class FailedGateFlow(Flow): """ Test that failed If gate not reflects on finished job """ lock_impl = lock.cache_lock start = flow.Start().Next(this.job) job = celery.Job(tasks.dummy_job).Next(this.iff) iff = flow.If(lambda p: 2 / 0).OnTrue(this.end).OnFalse(this.end) end = flow.End()
class AllTaskFlow(Flow): lock_impl = lock.cache_lock start = flow.Start().Next(this.view) view = flow.View(perform_task).Next(this.job) job = celery.Job(tasks.dummy_job).Next(this.iff) iff = flow.If(lambda act: True).OnTrue(this.switch).OnFalse(this.switch) switch = flow.Switch().Default(this.split) split = flow.Split().Always(this.join) join = flow.Join().Next(this.first) first = flow.First().Of(this.end) end = flow.End()
class LeaveFlow(Flow): process_class = LeaveProcess summary_template = "{{ process.leave.req_by.user.username }}的请假" process_title = '请假' start = (flow.Start(LeaveStartView).Permission(auto_create=True).Next( this.dep_approve)) dep_approve = ( flow.View(approve_check).Assign( #提交到自己的manager lambda act: act.process.leave.req_by.Manager.user).Next( this.check_dep_approve)) check_dep_approve = ( flow.If(lambda activation: activation.process.dep_approved == 1).Then( this.hr_approve).Else(this.NG)) hr_approve = ( flow.View(approve_check).Permission( #有权限就可以签收,给特定的人赋权就可以。 auto_create=True).Next(this.check_hr_approve)) check_hr_approve = ( flow.If(lambda activation: activation.process.hr_approved == 1).Then( this.OK).Else(this.NG)) NG = (flow.Handler(this.send_NG_request).Next(this.end)) OK = (flow.Handler(this.send_OK_request).Next(this.end)) end = flow.End() def send_NG_request(self, activation): print('dep_approved==>' + str(activation.process.dep_approved)) print('hr_approved==>' + str(activation.process.hr_approved)) print('NG') def send_OK_request(self, activation): #print(activation.process.leave.user) print('OK')
class FormalApprovalFlow(Flow): process_cls = formal_models.FormalApprovalProcess task_cls = formal_models.FormalApprovalTask lock_impl = lock.select_for_update_lock start = flow.Start(StartView).Next(this.approve) approve = flow.View(ApproveView, assign_view=AssignToView.as_view()).Next( this.check_approve) check_approve = flow.If(cond=lambda p: p.is_approved) \ .OnTrue(this.end).OnFalse(this.end) end = flow.End()