def get_task(self, request): pk = request.GET.get('pk') process_instance = get_or_none(ProcessInstance, pk=pk) if not process_instance: return None return Task(instance=process_instance, node=process_instance.cur_node, user=request.user)
def _get_groups(self, group_str): """ g[o.group] g[o.groups] g[11:admins] """ group_str = remove_brackets(group_str, 'g[') if '.' in group_str: return self.eval_as_list(group_str) pk = group_str.split(':')[0] group = get_or_none(Group, pk=pk) return [group] if group else []
def create_pinstance(self, process, submit=False): created_by = self.created_by if not isinstance(process, Process): process = get_or_none(Process, code=process) if not self.pk: self.save() instance = ProcessInstance.objects.create( process=process, created_by=created_by, content_object=self, cur_node=process.get_draft_active()) self.pinstance = instance self.save() # instance will save after self.save if submit: self.submit_process() return instance
def create_pinstance(self, process, submit=False): """ Create and set self.pinstance for this model :param process: Which process to use :param submit: Whether auto submit it after create :return: The created process instance """ created_by = self.created_by if not isinstance(process, Process): process = get_or_none(Process, code=process) if not self.pk: self.save() instance = ProcessInstance.objects.create( process=process, created_by=created_by, content_object=self, cur_node=process.get_draft_active()) self.pinstance = instance self.save() # instance will save after self.save if submit: self.submit_process() return instance
def get_task(self, request): # TODO admin may don't have task, need auto create a work item for admin wi_id = request.GET.get('wi_id') user = request.user return get_or_none(Task, Q(user=user) | Q(agent_user=user), id=wi_id)
def get_given_up_active(self): return get_or_none(Node, process=self, status='given up')
def get_rejected_active(self): return get_or_none(Node, process=self, status='rejected')
def get_draft_active(self): return get_or_none(Node, process=self, status='draft')
def get_leave(self, reason): return get_or_none(Leave, reason=reason)
def get_task(self, request): # TODO admin may don't have task, need auto create a work item for admin wi_id = request.GET.get('wi_id') user = request.user # 返回lbworkflow_task表查询结果集,查询条件为get_or_none()方法第2,3参数(同时满足) return get_or_none(Task, Q(user=user) | Q(agent_user=user), id=wi_id)
def test_get_or_none(self): self.assertEqual(None, get_or_none(Book, name='not exist')) self.assertEqual( 'book-01', get_or_none(Book, name='book-01').name)
def test_get_or_none(self): self.assertEqual(None, get_or_none(Book, name='not exist')) self.assertEqual('book-01', get_or_none(Book, name='book-01').name)