Beispiel #1
0
    def before_update(self, request, kwargs):
        receiver_id = request.data.get('receiver', None)
        project_id = request.data.get('project', None)
        if project_id is None:
            raise Exception('项目 id 不能为空!')

        if receiver_id is not None:
            task_id = str(kwargs['pk'])
            task = Task.objects.get(id=task_id)
            # 如果当前任务已经存在负责人
            if task.receiver:
                if receiver_id != task.receiver.id:
                    if task.receive_status.id == TaskStatus.objects.get(
                            key='accepted').id:
                        BusinessPublic.create_message(
                            task.sender.id,
                            task.receiver.id,
                            menu_id=2,
                            messages='该任务已被项目负责人移走了!')
                    request.data['is_published'] = 0
                    request.data[
                        'receive_status'] = BusinessPublic.GetTaskStatusIdByKey(
                            'assigned')
            else:
                request.data[
                    'receive_status'] = BusinessPublic.GetTaskStatusIdByKey(
                        'assigned')
        else:
            request.data[
                'receive_status'] = BusinessPublic.GetTaskStatusIdByKey(
                    'unassigned')
Beispiel #2
0
    def before_create(self, request):
        # 任务创建人
        request.data['sender'] = request.user.id
        # 上级主管
        request.data['superior'] = request.user.id

        # 获取该任务所属的项目 id
        project_id = request.data.get('project', None)
        if project_id is None:
            raise Exception('项目 id 不能为空!')

        project = Project.objects.get(id=project_id)
        # 将项目负责人作为该任务的审核员
        if project.receiver_id is not None:
            request.data['auditor'] = project.receiver_id

        if request.data.get('receiver', None):
            request.data[
                'receive_status'] = BusinessPublic.GetTaskStatusIdByKey(
                    'assigned')
        else:
            request.data[
                'receive_status'] = BusinessPublic.GetTaskStatusIdByKey(
                    'unassigned')
Beispiel #3
0
    def get(self, request, format=None):
        user_id = request.user.id

        user_role_list = self.get_user_roles(user_id)
        users = UserProfile.objects.filter(superior_id=user_id)

        users = self.filter_user(request, users)

        sign = True

        if '项目负责人' in user_role_list:
            sign = True
        elif '任务负责人' in user_role_list:
            sign = False

        list_objects = []

        if sign:
            for user in users:
                user_obj = {}
                user_obj["id"] = user.id
                user_obj["name"] = user.name
                list_objects.append(user_obj)
        else:
            for user in users:
                # tasks = Task.objects.filter(receiver_id=user.id, is_active=1, receive_status__lte=3)
                tasks = Task.objects.filter(
                    ~Q(receive_status=BusinessPublic.GetTaskStatusIdByKey(
                        'checked')),
                    receiver_id=user.id,
                    is_active=1)

                if len(tasks) > 0:
                    for task in tasks:
                        if task is not None:
                            dict_obj1 = {}
                            dict_obj1["user_id"] = user.id
                            dict_obj1["name"] = user.name
                            dict_obj1["task_type"] = task.task_type.name
                            dict_obj1["task_progress"] = task.progress
                            dict_obj1["task_name"] = task.name
                            dict_obj1["end_time"] = task.end_time
                            dict_obj1["leftdays"] = (
                                task.end_time -
                                datetime.datetime.now().date()).days + 1
                            dict_obj1[
                                "receive_status"] = task.receive_status.text
                            list_objects.append(dict_obj1)
                else:
                    dict_obj2 = {}
                    dict_obj2["user_id"] = user.id
                    dict_obj2["name"] = user.name
                    dict_obj2["task_type"] = ''
                    dict_obj2["task_progress"] = ''
                    dict_obj2["task_name"] = ''
                    dict_obj2["end_time"] = ''
                    dict_obj2["leftdays"] = ''
                    dict_obj2["receive_status"] = ''
                    list_objects.append(dict_obj2)

        return MykeyResponse(status=status.HTTP_200_OK,
                             msg='请求成功',
                             data=list_objects)