def update(self, task_id): form = TaskForm(request.form, csrf=False) form.set_id(task_id) if form.validate_on_submit(): task = TaskModel().get_by_id(task_id) data = form.form2dict() # a new type to update a model ret = task.update(data) return self.render_json(data=task.item()) else: return self.render_error(code=Code.form_error, message=form.errors)
def post(self): """ create a task /task/ :return: """ super(TaskAPI, self).post() form = TaskForm(request.form, csrf=False) if form.validate_on_submit(): task_new = TaskModel() data = form.form2dict() task_new_info = task_new.add(data) if not task_new_info: return self.render_json(code=-1) # 待审核 try: if task_new_info['status'] == TaskModel.status_new: project_info = ProjectModel( id=task_new_info['project_id']).item() space_id = project_info['space_id'] space_info = SpaceModel(id=space_id).item() task_url = Notice.task_url( project_space=space_info['name'], task_id=task_new_info['id']) notice_info = { 'title': '新上线单需要审核', 'username': current_user.username, 'project_name': project_info['name'], 'task_id': task_new_info['id'], 'task_url': task_url, 'task_name': task_new_info['name'], 'branch': task_new_info['branch'], 'commit': task_new_info['commit_id'], 'tag': task_new_info['tag'], 'repo_mode': project_info['repo_mode'], } Notice.create(Notice.by_dingding).audit_task( project_info, notice_info) except: pass return self.render_json(data=task_new_info) else: return self.render_error(code=Code.form_error, message=form.errors)
def post(self): """ create a task /task/ :return: """ super(TaskAPI, self).post() form = TaskForm(request.form, csrf=False) if form.validate_on_submit(): task_new = TaskModel() data = form.form2dict() task_new_info = task_new.add(data) if not task_new_info: return self.render_json(code=-1) return self.render_json(data=task_new_info) else: return self.render_error(code=Code.form_error, message=form.errors)
def post(self): """ create a task /task/ :return: """ super(TaskAPI, self).post() form = TaskForm(request.form, csrf_enabled=False) # return self.render_json(code=-1, data = form.form2dict()) if form.validate_on_submit(): task_new = TaskModel() data = form.form2dict() id = task_new.add(data) if not id: return self.render_json(code=-1) return self.render_json(data=task_new.item()) else: return self.render_json(code=-1, message=form.errors)