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))
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
 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
Ejemplo n.º 6
0
 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))
Ejemplo n.º 7
0
 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
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
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 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 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
Ejemplo n.º 15
0
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
Ejemplo n.º 16
0
 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