Ejemplo n.º 1
0
 def get(self, *args, **kwargs):
     tid = kwargs.get('tid')
     mode = kwargs.get('mode')
     if not tid:
         raise HTTPError(404)
     p_users = Auth.find_project_users(pid=self.pid)
     self.p_users = [{'id': auth.user_id, 'name': auth.user_name} for auth in p_users]
     self.json_p_users = json.dumps(self.p_users)
     task = Task.get(id=tid)
     if not mode:  # 任务详细信息
         # get comment
         task_comments = Comment.find(task_id=task.id, order_by='created')
         # get change log
         task_logs = TaskLog.find(task_id=task.id, order_by='created desc')
         # focus
         focus = TaskFocus.check_focus(task_id=task.id, user_id=self.user.id)
         return self.render('task.html',
                            task=task,
                            auth=self.auth,
                            logs=task_logs,
                            comments=task_comments,
                            focus=focus)
     if mode == 'solve':  # 标记解决任务
         if not task.is_done:
             task.status = Task._status_solved
             task.save()
             TaskLog.new(
                 task_id=task.id,
                 desc=json.dumps([]),
                 note=u'标记为解决',
                 updater_id=self.user.id,
                 updater_name=self.user.name,
             )
         return self.redirect('/%s/%s/%s' % (self.pid, 'task', task.id))
     if mode == 'edit':  # 编辑任务
         # 用户列表去除已经分配的用户
         users = [u for u in self.p_users if u['id'] not in task.assigned_ids]
         json_p_users = json.dumps(users)
         task_data = task.dictify()
         task_data['assigneds'] = json.dumps(task.assigned_users)
         return self.render(
             'task-new.html',
             task=task_data,
             auth=self.auth,
             json_users=json_p_users,
             statuses=self.statuses,
             types=self.types,
             priorities=self.priorities,
             errors={},
             update=True)
     if mode == 'focus':  # 关注任务
         TaskFocus.focus(
             task=task,
             user=self.user,
             pid=self.pid,
             pname=self.auth.project_name,
         )
         return self.redirect('/%s/%s/%s' % (self.pid, 'task', task.id))
Ejemplo n.º 2
0
 def get(self, *args, **kwargs):
     # todo 改善, 不要写多
     # todo 添加缓存
     p_users = Auth.find_project_users(pid=self.pid)
     p_users = [{'id': auth.user_id, 'name': auth.user_name} for auth in p_users]
     json_p_users = json.dumps(p_users)
     form = TaskForm()
     form.assigneds.data = json.dumps([])
     return self.render('task-new.html',
                        task=form.data,
                        auth=self.auth,
                        json_users=json_p_users,
                        statuses=self.statuses,
                        types=self.types,
                        priorities=self.priorities,
                        errors={},
                        update=False)
Ejemplo n.º 3
0
    def post(self, *args, **kwargs):
        # todo
        p_users = Auth.find_project_users(pid=self.pid)
        p_users = [{
            'id': auth.user_id,
            'name': auth.user_name
        } for auth in p_users]
        json_p_users = json.dumps(p_users)
        self.p_users = p_users  # form填充需要使用
        form = TaskForm(self, self.request.arguments)
        is_continue = int(self.get_args('continue', 0))
        if form.validate():
            form.created.data = datetime.now()
            data = dict(form.data)
            if not data['expires']:
                data.pop('expires')
            # return
            task = Task.new(**data)
            # 指派用户, 记录消息
            for ud in task.assigned_users:
                Message.set(user_id=ud['id'],
                            from_user=self.user,
                            task=task,
                            pid=self.pid,
                            pname=self.auth.project_name,
                            type='assigned')
            if task and is_continue:
                self.add_message(u'发布任务成功')
                return self.redirect(self.request.uri)
            return self.redirect('/%s/task' % self.pid)
        else:

            return self.render(
                'task-new.html',
                task=form.data,  # 字典
                auth=self.auth,
                json_users=json_p_users,
                statuses=self.statuses,
                types=self.types,
                priorities=self.priorities,
                errors=form.errors,
                update=False)
Ejemplo n.º 4
0
 def get(self, *args, **kwargs):
     # todo 改善, 不要写多
     # todo 添加缓存
     p_users = Auth.find_project_users(pid=self.pid)
     p_users = [{
         'id': auth.user_id,
         'name': auth.user_name
     } for auth in p_users]
     json_p_users = json.dumps(p_users)
     form = TaskForm()
     form.assigneds.data = json.dumps([])
     return self.render('task-new.html',
                        task=form.data,
                        auth=self.auth,
                        json_users=json_p_users,
                        statuses=self.statuses,
                        types=self.types,
                        priorities=self.priorities,
                        errors={},
                        update=False)
Ejemplo n.º 5
0
    def post(self, *args, **kwargs):
        # todo
        p_users = Auth.find_project_users(pid=self.pid)
        p_users = [{'id': auth.user_id, 'name': auth.user_name} for auth in p_users]
        json_p_users = json.dumps(p_users)
        self.p_users = p_users  # form填充需要使用
        form = TaskForm(self, self.request.arguments)
        is_continue = int(self.get_args('continue', 0))
        if form.validate():
            form.created.data = datetime.now()
            data = dict(form.data)
            if not data['expires']:
                data.pop('expires')
            # return
            task = Task.new(**data)
            # 指派用户, 记录消息
            for ud in task.assigned_users:
                Message.set(user_id=ud['id'],
                            from_user=self.user,
                            task=task,
                            pid=self.pid,
                            pname=self.auth.project_name,
                            type='assigned')
            if task and is_continue:
                self.add_message(u'发布任务成功')
                return self.redirect(self.request.uri)
            return self.redirect('/%s/task' % self.pid)
        else:

            return self.render(
                'task-new.html',
                task=form.data,  # 字典
                auth=self.auth,
                json_users=json_p_users,
                statuses=self.statuses,
                types=self.types,
                priorities=self.priorities,
                errors=form.errors,
                update=False)
Ejemplo n.º 6
0
 def post(self, *args, **kwargs):
     """ 编辑任务 并记录更新历史
     """
     tid = kwargs.get('tid')
     mode = kwargs.get('mode')
     if not tid or mode != 'edit':
         raise HTTPError(404)
     p_users = Auth.find_project_users(pid=self.pid)
     self.p_users = [{'id': auth.user_id, 'name': auth.user_name} for auth in p_users]
     self.json_p_users = json.dumps(self.p_users)
     task = Task.get(id=tid)
     post_data = self.request.arguments
     # log note
     log_note = post_data['note'][0].decode('utf8')
     form = TaskForm(self, post_data)
     # redefine task message
     form.creator_id.data = task.creator_id
     form.creator_name.data = task.creator_name
     form.project_id.data = self.pid
     form.created.data = task.created
     # 旧的指派者
     assigned_users = task.assigned_users
     if form.validate():
         task = task.update_and_log(
             data=form.data,
             actor_id=self.user.id,
             actor_name=self.user.name,
             note=log_note)
         if task:
             # 指派用户, 记录消息
             for ud in task.assigned_users:
                 Message.set(user_id=ud['id'],
                             from_user=self.user,
                             task=task,
                             pid=self.pid,
                             pname=self.auth.project_name,
                             type='assigned')
             # 删除更新 未指派用户的消息 为获取用户消息提供服务 物理删除记录
             del_msg_user_ids = [u['id'] for u in assigned_users if u['id'] not in task.assigned_ids]
             for duid in del_msg_user_ids:
                 Message.delete(
                     user_id=duid,
                     type=Message._type_assigned,
                     task_id=task.id,
                     project_id=self.pid
                 )
             # 任务更新消息
             if task.creator_id != self.user.id:
                 Message.set(
                     user_id=task.creator_id,
                     from_user=self.user,
                     task=task,
                     pid=self.pid,
                     pname=self.auth.project_name,
                     type='edit'
                 )
             return self.redirect('/%s/task/%s' % (self.pid, task.id))
         self.add_message(u'更新任务失败, 请重试')
         return self.render('failed.html')
     else:
         # 去除已经填写的用户
         assigneds = json.loads(form.assigneds.data)
         aids = set([ud['id'] for ud in assigneds])
         json_users = json.dumps([ud for ud in self.p_users if ud['id'] not in aids])
         return self.render(
             'task-new.html',
             task=form.data,
             auth=self.auth,
             json_users=json_users,
             statuses=self.statuses,
             types=self.types,
             priorities=self.priorities,
             errors=form.errors,
             update=True)
Ejemplo n.º 7
0
 def post(self, *args, **kwargs):
     """ 编辑任务 并记录更新历史
     """
     tid = kwargs.get('tid')
     mode = kwargs.get('mode')
     if not tid or mode != 'edit':
         raise HTTPError(404)
     p_users = Auth.find_project_users(pid=self.pid)
     self.p_users = [{
         'id': auth.user_id,
         'name': auth.user_name
     } for auth in p_users]
     self.json_p_users = json.dumps(self.p_users)
     task = Task.get(id=tid)
     post_data = self.request.arguments
     # log note
     log_note = post_data['note'][0].decode('utf8')
     form = TaskForm(self, post_data)
     # redefine task message
     form.creator_id.data = task.creator_id
     form.creator_name.data = task.creator_name
     form.project_id.data = self.pid
     form.created.data = task.created
     # 旧的指派者
     assigned_users = task.assigned_users
     if form.validate():
         task = task.update_and_log(data=form.data,
                                    actor_id=self.user.id,
                                    actor_name=self.user.name,
                                    note=log_note)
         if task:
             # 指派用户, 记录消息
             for ud in task.assigned_users:
                 Message.set(user_id=ud['id'],
                             from_user=self.user,
                             task=task,
                             pid=self.pid,
                             pname=self.auth.project_name,
                             type='assigned')
             # 删除更新 未指派用户的消息 为获取用户消息提供服务 物理删除记录
             del_msg_user_ids = [
                 u['id'] for u in assigned_users
                 if u['id'] not in task.assigned_ids
             ]
             for duid in del_msg_user_ids:
                 Message.delete(user_id=duid,
                                type=Message._type_assigned,
                                task_id=task.id,
                                project_id=self.pid)
             # 任务更新消息
             if task.creator_id != self.user.id:
                 Message.set(user_id=task.creator_id,
                             from_user=self.user,
                             task=task,
                             pid=self.pid,
                             pname=self.auth.project_name,
                             type='edit')
             return self.redirect('/%s/task/%s' % (self.pid, task.id))
         self.add_message(u'更新任务失败, 请重试')
         return self.render('failed.html')
     else:
         # 去除已经填写的用户
         assigneds = json.loads(form.assigneds.data)
         aids = set([ud['id'] for ud in assigneds])
         json_users = json.dumps(
             [ud for ud in self.p_users if ud['id'] not in aids])
         return self.render('task-new.html',
                            task=form.data,
                            auth=self.auth,
                            json_users=json_users,
                            statuses=self.statuses,
                            types=self.types,
                            priorities=self.priorities,
                            errors=form.errors,
                            update=True)
Ejemplo n.º 8
0
 def get(self, *args, **kwargs):
     tid = kwargs.get('tid')
     mode = kwargs.get('mode')
     if not tid:
         raise HTTPError(404)
     p_users = Auth.find_project_users(pid=self.pid)
     self.p_users = [{
         'id': auth.user_id,
         'name': auth.user_name
     } for auth in p_users]
     self.json_p_users = json.dumps(self.p_users)
     task = Task.get(id=tid)
     if not mode:  # 任务详细信息
         # get comment
         task_comments = Comment.find(task_id=task.id, order_by='created')
         # get change log
         task_logs = TaskLog.find(task_id=task.id, order_by='created desc')
         # focus
         focus = TaskFocus.check_focus(task_id=task.id,
                                       user_id=self.user.id)
         return self.render('task.html',
                            task=task,
                            auth=self.auth,
                            logs=task_logs,
                            comments=task_comments,
                            focus=focus)
     if mode == 'solve':  # 标记解决任务
         if not task.is_done:
             task.status = Task._status_solved
             task.save()
             TaskLog.new(
                 task_id=task.id,
                 desc=json.dumps([]),
                 note=u'标记为解决',
                 updater_id=self.user.id,
                 updater_name=self.user.name,
             )
         return self.redirect('/%s/%s/%s' % (self.pid, 'task', task.id))
     if mode == 'edit':  # 编辑任务
         # 用户列表去除已经分配的用户
         users = [
             u for u in self.p_users if u['id'] not in task.assigned_ids
         ]
         json_p_users = json.dumps(users)
         task_data = task.dictify()
         task_data['assigneds'] = json.dumps(task.assigned_users)
         return self.render('task-new.html',
                            task=task_data,
                            auth=self.auth,
                            json_users=json_p_users,
                            statuses=self.statuses,
                            types=self.types,
                            priorities=self.priorities,
                            errors={},
                            update=True)
     if mode == 'focus':  # 关注任务
         TaskFocus.focus(
             task=task,
             user=self.user,
             pid=self.pid,
             pname=self.auth.project_name,
         )
         return self.redirect('/%s/%s/%s' % (self.pid, 'task', task.id))