예제 #1
0
    def convertToDict(self, type=None):

        start_date = ModelUtils.timeToStr(self.start_date)
        end_date = ModelUtils.timeToStr(self.end_date)

        if type == "pr":
            prs = self.progressReqs()

            return {
                'task_name': self.name,
                'prs': ModelUtils.objectsToDict(prs)
            }

        if type == "project":
            return {
                'id': self.id,
                'name': self.name,
                'progress': self.progress,
                'level': self.level,
                'status_id': self.status,
                'start_date': start_date,
                'end_date': end_date,
            }

        if type == "detail":
            return self.convertToDict()

        create_time = ModelUtils.timeToStr(self.create_time)

        return {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'project_id': self.project.id,
            'project_name': self.project.name,
            'parent_id': self.parent.id,
            'parent_name': self.parent.name,
            'status_id': self.status,
            'level': self.level,
            'progress': self.progress,
            'auto_adjust': self.auto_adjust,
            'create_time': create_time,
            'start_date': start_date,
            'end_date': end_date,
        }
예제 #2
0
    def convertToDict(self, type=None):

        # 获取索引信息
        if type == "index":
            return {
                'id': self.id,
                'name': self.name,
            }

        if type == "pr":
            tasks = self.tasks()
            return {'tasks': ModelUtils.objectsToDict(tasks, type='pr')}

        # 汇总信息
        if type == "total":

            sum_tasks, unstart_tasks, started_tasks, \
             finished_tasks, progress = self.analayTasks()

            return {
                'name': "汇总",
                'sum_tasks': sum_tasks,
                'unstart_tasks': unstart_tasks,
                'started_tasks': started_tasks,
                'finished_tasks': finished_tasks,
                'progress': progress / sum_tasks,
                'total': True
            }

        if type == "notices":
            notices = self.notice_set.all()
            creator = self.creator()
            return {
                'id': self.id,
                'name': self.name,
                'creator_id': creator.id,
                'creator_name': creator.name,
                'notices': ModelUtils.objectsToDict(notices)
            }

        # 获取成员视图数据
        if type == "members":

            ann = self.tasks().annotate(
                req_cnt=Count('taskprogress__id', distinct=True))
            agg = ann.aggregate(req_cnt=Sum('req_cnt'))

            members = self.members()

            member_info = ModelUtils.objectsToDict(members,
                                                   type="member_info",
                                                   proj=self)
            member_task = ModelUtils.objectsToDict(members,
                                                   type="member_task",
                                                   proj=self)

            for i in range(members.count()):
                # 玩家是否处于空闲状态 = 进行中的任务数是否为 0
                member_info[i]['is_free'] = \
                 member_task[i]['started_tasks'] == 0
                member_task[i]['rids'] = member_info[i]['rids']

            member_task.append(self.convertToDict('total'))

            return {
                'req_cnt': agg['req_cnt'],
                'member_info': member_info,
                'member_task': member_task,
            }

        chat_id = ModelUtils.objectToId(self.chat)
        create_time = ModelUtils.timeToStr(self.create_time)
        start_date = ModelUtils.timeToStr(self.start_date)
        end_date = ModelUtils.timeToStr(self.end_date)

        res = {
            'id': self.id,
            'name': self.name,
            'type_id': self.type,
            'description': self.description,
            'create_time': create_time,
            'start_date': start_date,
            'end_date': end_date,
            'chat_id': chat_id
        }

        # 获取详情信息(用于详情页展示)
        if type == "detail":

            members = ModelUtils.objectsToDict(self.members(),
                                               type="member",
                                               proj=self)
            tasks = ModelUtils.objectsToDict(self.tasks(True), type="project")

            res['members'] = members
            res['tasks'] = tasks

        return res
예제 #3
0
    def convertToDict(self, type=None, **args):

        create_time = ModelUtils.timeToStr(self.create_time)

        from project_module.models import Project

        # 获取陌生人的资料
        if type == 'stranger':
            return {
                'id': self.id,
                'username': self.username,
                'gender': int(self.gender),
                'avatar': self.avatar.name,
                'description': self.description,
                'status_id': self.status,
            }

        # 获取队伍成员资料
        if type == 'member' and 'proj' in args:
            proj: Project = args['proj']
            return {
                'id': self.id,
                'name': self.name,
                'contact': self.contact,
                'rids': proj.getRoleIds(self),
            }

        if type == 'member_info' and 'proj' in args:
            proj: Project = args['proj']
            return {
                'id': self.id,
                'name': self.name,
                'gender': int(self.gender),
                'rids': proj.getRoleIds(self),
                'email': self.email,
                'contact': self.contact,
                'status_id': self.status
            }

        if type == 'member_task' and 'proj' in args:
            proj: Project = args['proj']

            member_tasks = proj.getMemberTasks(self)
            sum_tasks, unstart_tasks, started_tasks, finished_tasks, \
             progress = proj.analayTasks(member_tasks)

            return {
                'id': self.id,
                'name': self.name,
                'sum_tasks': sum_tasks,
                'unstart_tasks': unstart_tasks,
                'started_tasks': started_tasks,
                'finished_tasks': finished_tasks,
                'progress': progress / sum_tasks
            }

        # 获取好友的资料
        if type == 'friend':
            return self.convertToDict()

        # 获取好友列表(已接受的)
        if type == 'friends':
            return {
                'friends': ModelUtils.objectsToDict(self.getFriends(),
                                                    uid=self.id)
            }

        # 获取发起好友请求列表
        if type == 'send_reqs':
            return {
                'reqs':
                ModelUtils.objectsToDict(self.getSendFriendReqs(), type='send')
            }
        # 获取发起好友请求列表
        if type == 'received_reqs':
            return {
                'reqs':
                ModelUtils.objectsToDict(self.getReceivedFriendReqs(),
                                         type='received')
            }
        # 个人详细资料
        return {
            'id': self.id,
            'username': self.username,
            'email': self.email,
            'name': self.name,
            'gender': int(self.gender),
            'avatar': self.avatar.name,
            'birth': self.birth,
            'city': self.city,
            'education_id': self.education,
            'duty': self.duty,
            'contact': self.contact,
            'description': self.description,
            'create_time': create_time,
            'status_id': self.status,
        }