def patch(self, config_key): config = Configs.query.filter_by(key=config_key).first() data = request.get_json() if config: schema = ConfigSchema(instance=config, partial=True) response = schema.load(data) else: schema = ConfigSchema() data['key'] = config_key response = schema.load(data) db.session.add(response.data) if response.errors: return response.errors, 400 db.session.commit() response = schema.dump(response.data) db.session.close() clear_config() clear_standings() return { 'success': True, 'data': response.data }
def patch(self): req = request.get_json() schema = ConfigSchema() for key, value in req.items(): response = schema.load({"key": key, "value": value}) if response.errors: return {"success": False, "errors": response.errors}, 400 set_config(key=key, value=value) clear_config() clear_standings() return {"success": True}
def post(self): req = request.get_json() schema = ConfigSchema() response = schema.load(req) if response.errors: return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() clear_config() clear_standings() return {"success": True, "data": response.data}
def patch(self): req = request.get_json() schema = ConfigSchema() for key, value in req.items(): response = schema.load({"key": key, "value": value}) if response.errors: # Inject config key into error config_key = response.data["key"] response.errors["value"][ 0] = f"{config_key} config is too long" return {"success": False, "errors": response.errors}, 400 set_config(key=key, value=value) clear_config() clear_standings() return {"success": True}
def post(self): req = request.get_json() schema = ConfigSchema() response = schema.load(req) if response.errors: # Inject config key into error config_key = response.data["key"] response.errors["value"][0] = f"{config_key} config is too long" return {"success": False, "errors": response.errors}, 400 db.session.add(response.data) db.session.commit() response = schema.dump(response.data) db.session.close() clear_config() clear_standings() return {"success": True, "data": response.data}