Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
* ``delete_list`` (requires authentication)
Users may also wish to define a ``fields`` attribute on the class. By
providing a dictionary of output names mapped to a dotted lookup path, you
can control the serialized output.
Users may also choose to override the ``status_map`` and/or ``http_methods``
on the class. These respectively control the HTTP status codes returned by
the views and the way views are looked up (based on HTTP method & endpoint).
"""
status_map = {
'list': OK,
'detail': OK,
'create': CREATED,
'update': ACCEPTED,
'delete': NO_CONTENT,
'update_list': ACCEPTED,
'create_detail': CREATED,
'delete_list': NO_CONTENT,
}
http_methods = {
'list': {
'GET': 'list',
'POST': 'create',
'PUT': 'update_list',
'DELETE': 'delete_list',
},
'detail': {
'GET': 'detail',
'POST': 'create_detail',
'PUT': 'update',
'DELETE': 'delete',
def build_response(self, data, status=OK):
if status == NO_CONTENT:
# Avoid crashing the client when it tries to parse nonexisting JSON.
content_type = 'text/plain'
else:
content_type = 'application/json'
self.ref_rh.set_header("Content-Type", "{}; charset=UTF-8"
.format(content_type))
self.ref_rh.set_status(status)
self.ref_rh.finish(data)
def build_response(self, data, status=OK):
if status == NO_CONTENT:
# Avoid crashing the client when it tries to parse nonexisting JSON.
content_type = 'text/plain'
else:
content_type = 'application/json'
resp = HttpResponse(data, content_type=content_type, status=status)
return resp
def build_response(self, data, status=OK):
if status == NO_CONTENT:
# Avoid crashing the client when it tries to parse nonexisting JSON.
content_type = 'text/plain'
else:
content_type = 'application/json'
resp = Response(data, status_code=status, content_type=content_type)
return resp
def build_response(self, data, status=OK):
if status == NO_CONTENT:
# Avoid crashing the client when it tries to parse nonexisting JSON.
content_type = 'text/plain'
else:
content_type = 'application/json'
return make_response(data, status, {
'Content-Type': content_type,
})