def put(self, project_id, action=None): """ update project /project/<int:id> :return: """ super(ProjectAPI, self).put() if action and action == 'members': return self.members(project_id, members=json.loads(request.data.decode('utf-8'))) form = ProjectForm(request.form, csrf=False) form.set_id(project_id) if form.validate_on_submit(): server = ProjectModel().get_by_id(project_id) repo_url_origin = server.repo_url data = form.form2dict() # a new type to update a model ret = server.update(data) # maybe sth changed by git if repo_url_origin != data['repo_url']: dir_codebase_project = current_app.config.get('CODE_BASE') + str(project_id) if os.path.exists(dir_codebase_project): shutil.rmtree(dir_codebase_project) return self.render_json(data=server.item()) else: return self.render_error(code=Code.form_error, message=form.errors)
def create(self): form = ProjectForm(request.form, csrf=False) if form.validate_on_submit(): # add project project = ProjectModel() data = form.form2dict() project_new = project.add(data) if not project_new: return self.render_json(code=-1) return self.render_json(data=project_new) else: return self.render_error(code=Code.form_error, message=form.errors)
def post(self): """ create a project /environment/ :return: """ super(ProjectAPI, self).post() form = ProjectForm(request.form, csrf_enabled=False) if form.validate_on_submit(): project_new = ProjectModel() data = form.form2dict() id = project_new.add(data) if not id: return self.render_json(code=-1) return self.render_json(data=project_new.item()) else: return self.render_json(code=-1, message=form.errors)
def put(self, project_id, action=None): """ update environment /environment/<int:id> :return: """ super(ProjectAPI, self).put() if action and action == 'members': return self.members(project_id, members=json.loads(request.data)) form = ProjectForm(request.form, csrf_enabled=False) form.set_id(project_id) if form.validate_on_submit(): server = ProjectModel().get_by_id(project_id) data = form.form2dict() # a new type to update a model ret = server.update(data) return self.render_json(data=server.item()) else: return self.render_json(code=-1, message=form.errors)