Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
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)