def update(self): try: update = getattr(self.model, model_fn(self, 'update')) except AttributeError: e = InvalidOperation('KCHAPI0003E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) params = parse_request() validate_params(params, self, 'update') if self.update_params is not None: invalids = [v for v in params.keys() if v not in self.update_params] if invalids: msg_args = {'params': ", ".join(invalids), 'resource': get_class_name(self)} e = InvalidOperation('KCHAPI0004E', msg_args) raise cherrypy.HTTPError(405, e.message) args = list(self.model_args) + [params] ident = update(*args) self._redirect(ident) return self.get()
def update(self): try: update = getattr(self.model, model_fn(self, 'update')) except AttributeError: e = InvalidOperation('KCHAPI0003E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) params = parse_request() validate_params(params, self, 'update') if self.update_params is not None: invalids = [ v for v in params.keys() if v not in self.update_params ] if invalids: msg_args = { 'params': ", ".join(invalids), 'resource': get_class_name(self) } e = InvalidOperation('KCHAPI0004E', msg_args) raise cherrypy.HTTPError(405, e.message) args = list(self.model_args) + [params] ident = update(*args) self._redirect(ident) return self.get()
def index(self, *args, **kwargs): method = validate_method(('GET', 'POST')) if method == 'GET': try: filter_params = cherrypy.request.params validate_params(filter_params, self, 'get_list') return self.get(filter_params) except InvalidOperation, e: raise cherrypy.HTTPError(400, e.message) except NotFoundError, e: raise cherrypy.HTTPError(404, e.message)
def index(self, *args, **kwargs): method = validate_method(('GET', 'POST')) try: if method == 'GET': filter_params = cherrypy.request.params validate_params(filter_params, self, 'get_list') return self.get(filter_params) elif method == 'POST': return self.create(parse_request(), *args) except InvalidOperation, e: raise cherrypy.HTTPError(400, e.message)
def index(self, *args, **kwargs): method = validate_method(('GET', 'POST')) if method == 'GET': try: filter_params = cherrypy.request.params validate_params(filter_params, self, 'get_list') return self.get(filter_params) except InvalidOperation, param: error = "Invalid operation: '%s'" % param raise cherrypy.HTTPError(400, error) except NotFoundError, param: raise cherrypy.HTTPError(404, "Not found: '%s'" % param)
def create(self, params, *args): try: create = getattr(self.model, model_fn(self, 'create')) except AttributeError: e = InvalidOperation('KCHAPI0005E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) validate_params(params, self, 'create') args = self.model_args + [params] task = create(*args) cherrypy.response.status = 202 return kimchi.template.render("Task", task)
def create(self, params, *args): try: create = getattr(self.model, model_fn(self, 'create')) except AttributeError: e = InvalidOperation('KCHAPI0005E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) validate_params(params, self, 'create') args = self.model_args + [params] name = create(*args) cherrypy.response.status = 201 args = self.resource_args + [name] res = self.resource(self.model, *args) return res.get()
def update(self, *args, **kargs): try: update = getattr(self.model, model_fn(self, 'update')) except AttributeError: e = InvalidOperation('KCHAPI0003E', {'resource': get_class_name(self)}) raise cherrypy.HTTPError(405, e.message) params = parse_request() validate_params(params, self, 'update') args = list(self.model_args) + [params] ident = update(*args) self._redirect(ident) return self.get()
def create(self, *args): try: create = getattr(self.model, model_fn(self, 'create')) except AttributeError: error = 'Create is not allowed for %s' % get_class_name(self) raise cherrypy.HTTPError(405, error) params = parse_request() validate_params(params, self, 'create') args = self.model_args + [params] name = create(*args) cherrypy.response.status = 201 args = self.resource_args + [name] res = self.resource(self.model, *args) return res.get()
def create(self, params, *args): try: create = getattr(self.model, model_fn(self, 'create')) except AttributeError: error = 'Create is not allowed for %s' % get_class_name(self) raise cherrypy.HTTPError(405, error) validate_params(params, self, 'create') args = self.model_args + [params] name = create(*args) args = self.resource_args + [name] res = self.resource(self.model, *args) resp = res.get() if 'task_id' in res.data: cherrypy.response.status = 202 else: cherrypy.response.status = 201 return resp
def update(self): try: update = getattr(self.model, model_fn(self, 'update')) except AttributeError: error = "%s does not implement update method" raise cherrypy.HTTPError(405, error % get_class_name(self)) params = parse_request() validate_params(params, self, 'update') if self.update_params is not None: invalids = [v for v in params.keys() if v not in self.update_params] if invalids: error = "%s are not allowed to be updated" % invalids raise cherrypy.HTTPError(405, error) ident = update(self.ident, params) if ident != self.ident: uri_params = list(self.model_args[:-1]) uri_params += [urllib2.quote(ident.encode('utf8'))] raise cherrypy.HTTPRedirect(self.uri_fmt % tuple(uri_params), 303) return self.get()