def count_link_or_reference(self, req, resp, id, link_name): kwargs = self.parse_params(req) kwargs['count'] = True result = self.interface.link(id, link_name, **kwargs) resp.content_type, _ = View.choose(req.get_header('accept'), self.views) if isinstance(result, int): resp.set_header('X-Count', str(result))
def duplicate_field_error(views, exc, req, resp, params): error = {} error[exc.message] = 'A duplicate value already exists.' _, view = View.choose(req.get_header('accept'), views) resp.content_type, resp.body = view.get_individual_response( req.get_header('accept'), error) resp.status = falcon.HTTP_400
def count(self, req, resp): kwargs = self.parse_params(req) kwargs['count'] = True result = self.interface.list(**kwargs) resp.content_type, _ = View.choose(req.get_header('accept'), self.views) resp.set_header('X-Count', str(result))
def head(self): kwargs = self.parse_params() kwargs['count'] = True count = self.interface.list(**kwargs) res = make_response('') res.headers['Content-Type'], _ = View.choose(request.headers.get('accept'), self.views) res.headers['X-Count'] = str(count) return res
def response(self, content, status_code=200): _, view = View.choose(request.headers.get('accept'), self.views) serialize_fn = view.get_list_response if isinstance(content, collections.Sequence) else view.get_individual_response content_type, body = serialize_fn(request.headers.get('accept'), content) res = make_response(body) res.status_code = status_code res.headers['content-type'] = content_type return res
def head(self): kwargs = self.parse_params() kwargs['count'] = True count = self.interface.list(**kwargs) res = make_response('') res.headers['Content-Type'], _ = View.choose( request.headers.get('accept'), self.views) res.headers['X-Count'] = str(count) return res
def error_response(code, item=None, views=[]): if not item: abort(code) else: _, view = View.choose(request.headers.get('accept'), views) content_type, body = view.get_individual_response(request.headers.get('accept'), item) res = make_response(body) res.status_code = code res.headers['content-type'] = content_type return res
def response(self, content, status_code=200): _, view = View.choose(request.headers.get('accept'), self.views) serialize_fn = view.get_list_response if isinstance( content, collections.Sequence) else view.get_individual_response content_type, body = serialize_fn(request.headers.get('accept'), content) res = make_response(body) res.status_code = status_code res.headers['content-type'] = content_type return res
def error_response(code, item=None, views=[]): if not item: abort(code) else: _, view = View.choose(request.headers.get('accept'), views) content_type, body = view.get_individual_response( request.headers.get('accept'), item) res = make_response(body) res.status_code = code res.headers['content-type'] = content_type return res
def duplicate_field_error(views, exc, req, resp, params): error = {} error[exc.message] = 'A duplicate value already exists.' _, view = View.choose(req.get_header('accept'), views) resp.content_type, resp.body = view.get_individual_response(req.get_header('accept'), error) resp.status = falcon.HTTP_400
def validation_error_handler(views, exc, req, resp, params): _, view = View.choose(req.get_header('accept'), views) resp.content_type, resp.body = view.get_individual_response(req.get_header('accept'), exc.errors) resp.status = falcon.HTTP_400
def get_view(self, req): """Get the correct view based on the Accept header""" _, view = View.choose(req.get_header('accept'), self.views) return view
def validation_error_handler(views, exc, req, resp, params): _, view = View.choose(req.get_header('accept'), views) resp.content_type, resp.body = view.get_individual_response( req.get_header('accept'), exc.errors) resp.status = falcon.HTTP_400