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 login(self, *args): params = parse_request() try: userid = params['userid'] password = params['password'] except KeyError, item: e = MissingParameter('KCHAUTH0003E', {'item': str(item)}) raise cherrypy.HTTPError(400, e.message)
def login(self, *args): params = parse_request() try: username = params['username'] password = params['password'] except KeyError, item: e = MissingParameter('KCHAUTH0003E', {'item': str(item)}) raise cherrypy.HTTPError(400, 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 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() args = self.model_args + [params] task = create(*args) cherrypy.response.status = 202 return kimchi.template.render("Task", task)
def wrapper(*args, **kwargs): validate_method(('POST')) try: model_args = list(self.model_args) if action_args is not None: model_args.extend(parse_request()[key] for key in action_args) fn = getattr(self.model, model_fn(self, action_name)) fn(*model_args) uri_params = tuple(self.model_args) raise internal_redirect(self.uri_fmt % uri_params) except MissingParameter, param: error = "Missing parameter: '%s'" % param raise cherrypy.HTTPError(400, error)
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 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 wrapper(*args, **kwargs): validate_method(('POST'), self.role_key, self.admin_methods) try: self.lookup() if not self.is_authorized(): raise UnauthorizedError('KCHAPI0009E') model_args = list(self.model_args) if action_args is not None: request = parse_request() model_args.extend(request[key] for key in action_args) action_fn = getattr(self.model, model_fn(self, action_name)) action_result = action_fn(*model_args) return render_fn(self, action_result) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message)
def wrapper(*args, **kwargs): validate_method(('POST')) try: model_args = list(self.model_args) if action_args is not None: request = parse_request() model_args.extend(request[key] for key in action_args) fn = getattr(self.model, model_fn(self, action_name)) ident = fn(*model_args) self._redirect(ident) uri_params = [] for arg in self.model_args: if arg is None: arg = '' uri_params.append(urllib2.quote(arg.encode('utf-8'), safe="")) raise internal_redirect(self.uri_fmt % tuple(uri_params)) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message)
def wrapper(*args, **kwargs): validate_method(('POST')) try: model_args = list(self.model_args) if action_args is not None: request = parse_request() model_args.extend(request[key] for key in action_args) fn = getattr(self.model, model_fn(self, action_name)) ident = fn(*model_args) self._redirect(ident) uri_params = [] for arg in self.model_args: if arg is None: arg = '' uri_params.append( urllib2.quote(arg.encode('utf-8'), safe="")) raise internal_redirect(self.uri_fmt % tuple(uri_params)) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message)
def wrapper(*args, **kwargs): validate_method(('POST'), self.role_key, self.admin_methods) try: self.lookup() if not self.is_authorized(): raise UnauthorizedError('KCHAPI0009E') model_args = list(self.model_args) if action_args is not None: request = parse_request() model_args.extend(request[key] for key in action_args) action_fn = getattr(self.model, model_fn(self, action_name)) action_result = action_fn(*model_args) if destructive is False or \ ('persistent' in self.info.keys() and self.info['persistent'] is True): return render_fn(self, action_result) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message)
def login(self, *args, **kwargs): username = kwargs.get("username") password = kwargs.get("password") # forms base authentication if username is not None: next_url = cherrypy.request.cookie.get("lastPage") if next_url is None: # UI can parser the redirect url by "next" query parameter next_url = kwargs.get("next", "/") next_url = next_url[0] if (type(next_url) is list) else next_url else: next_url = next_url.value auth.login(username, password) raise cherrypy.HTTPRedirect(next_url, 303) else: try: params = parse_request() username = params["username"] password = params["password"] except KeyError, item: e = MissingParameter("KCHAUTH0003E", {"item": str(item)}) raise cherrypy.HTTPError(400, e.message)
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()
@cherrypy.expose 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) elif method == 'POST': try: return self.create(parse_request(), *args) except MissingParameter, e: raise cherrypy.HTTPError(400, e.message) except InvalidParameter, e: raise cherrypy.HTTPError(400, e.message) except OperationFailed, e: raise cherrypy.HTTPError(500, e.message) except InvalidOperation, e: raise cherrypy.HTTPError(400, e.message) except NotFoundError, e: raise cherrypy.HTTPError(404, e.message) class AsyncCollection(Collection): """ A Collection to create it's resource by asynchronous task