def deliver(self, id): Workflow = functions.get_workflow() obj = self.model.get(int(id)) workflow = Workflow.load(obj._workflow_, operator=request.user) if workflow.is_running(): tasks = workflow.get_active_tasks() if len(tasks) == 1: task_id = tasks[0].get_unique_id() next_tasks = tasks[0].get_next_tasks() from_task_id = request.POST.get('from_task_id') if from_task_id != task_id: return json({'success': False, 'message': '无效的标识,请求的活动可能已经被他人流转。'}) trans_message = request.POST.get('trans_message', '') to_task = request.POST.get('to_task', None) if not to_task: return json({'success': False, 'message': '无效的请求,您没有指定需要流转的流向。'}) tasks[0].deliver(trans_message, next_tasks=[to_task], async=False) obj.approve_result = to_task obj.approver = request.user.id obj.approver_date = datetime.datetime.now() obj.save() workflow.run() return json({'success': True}) else: return json({'success': False, 'message': '无效的请求,请求的活动可能已经被他人流转。'})
def test(self): from uliweb import functions Workflow = functions.get_workflow() WORKFLOW_SPEC_NAME = "TestWorkflow1" #create some workflows n = 5 for i in range(0, n): workflow = Workflow.create(WORKFLOW_SPEC_NAME) workflow.ref_unique_id = "wf%s" % (i + 1) workflow.start() tasks = workflow.get_active_tasks() print "Create workflow %s" % workflow.ref_unique_id TaskDB = functions.get_model('workflow_task') while True: cond = TaskDB.c.state == '1' # ACTIVE query = TaskDB.filter(cond) print "loop -------------------------------------" ids = [task_obj.id for task_obj in query] if ids: print "ids: %s" % ids for aid in ids: task_obj = TaskDB.get(aid) #print "task_obj.id -- %d" % task_obj.id wf_id = task_obj._workflow_ workflow = Workflow.load(wf_id) #print "deliver workflow %s" % workflow.ref_unique_id tasks = workflow.get_active_tasks() if len(tasks) == 1: task_id = tasks[0].get_unique_id() task_name = tasks[0].get_name() next_tasks = tasks[0].get_next_tasks() # print "tasks - %s" %task_name if len(next_tasks) > 1: to_tasks = next_tasks[0][0] workflow.deliver(task_id, message="Auto", next_tasks=[to_tasks], async=False) else: workflow.deliver(task_id, message="Auto", async=False) else: break print "Done"
def post_save(obj, data): Workflow = functions.get_workflow() workflow = Workflow.create("YesNoWorkflow", operator=request.user) workflow.ref_unique_id = "yesno,%d" % obj.id workflow.start() workflow.run() obj.workflow = workflow.get_id() obj.save()
def test(self): from uliweb import functions Workflow = functions.get_workflow() WORKFLOW_SPEC_NAME = "TestWorkflow1" #create some workflows n = 5 for i in range(0, n): workflow = Workflow.create(WORKFLOW_SPEC_NAME) workflow.ref_unique_id = "wf%s" % (i+1) workflow.start() tasks = workflow.get_active_tasks() print "Create workflow %s" % workflow.ref_unique_id TaskDB = functions.get_model('workflow_task') while True: cond = TaskDB.c.state == '1' # ACTIVE query = TaskDB.filter(cond) print "loop -------------------------------------" ids = [task_obj.id for task_obj in query] if ids: print "ids: %s" % ids for aid in ids: task_obj = TaskDB.get(aid) #print "task_obj.id -- %d" % task_obj.id wf_id = task_obj._workflow_ workflow = Workflow.load(wf_id) #print "deliver workflow %s" % workflow.ref_unique_id tasks = workflow.get_active_tasks() if len(tasks) == 1: task_id = tasks[0].get_unique_id() task_name = tasks[0].get_name() next_tasks = tasks[0].get_next_tasks() # print "tasks - %s" %task_name if len(next_tasks)>1: to_tasks = next_tasks[0][0] workflow.deliver(task_id, message="Auto", next_tasks=[to_tasks], async=False) else: workflow.deliver(task_id, message="Auto", async=False) else: break print "Done"
def view(self, id): from uliweb.utils.generic import DetailView Workflow = functions.get_workflow() obj = self.model.get(int(id)) workflow = Workflow.load(obj._workflow_, operator=request.user) view = DetailView(self.model, obj=obj) result = view.run() data = { 'detailview': result['view'], 'obj': result['object'], 'workflow': workflow, 'task_desc': None, } if workflow.is_running(): tasks = workflow.get_active_tasks() if len(tasks) == 1: next_tasks = tasks[0].get_next_tasks() data.update({ 'show_deliver_form':True, 'deliverform': get_yesno_form(tasks[0], next_tasks), 'task_desc': tasks[0].get_desc(), 'task_name': tasks[0].get_name(), }) else: data.update({ 'show_deliver_form':False, }) else: data.update({'show_deliver_form': False}) return data