def _format_response(self, request, response): """ Format response using appropriate datamapper. Take the devil response and turn it into django response, ready to be returned to the client. """ res = datamapper.format(request, response, self) # data is now formatted, let's check if the status_code is set if res.status_code is 0: res.status_code = 200 # apply headers self._add_resposne_headers(res, response) return res
def _format_response(self, request, response): """ Format response. If the response is `HttpResponse`, does nothing. Otherwise, formats the response using appropriate mapper. :param response: resource's response. This can be - `None`, - django's `HttpResponse` - devil's `Response` - dictionary (or list of dictionaries) - plaintext """ if isinstance(response, HttpResponse): return response res = datamapper.format(request, response, self) # data is now formatted, let's check if the status_code is set if res.status_code is 0: res.status_code = 200 # apply headers self._add_resposne_headers(res, response) return res
def _format_response(self, request, response): """ Format response. If the response is `HttpResponse`, does nothing. Otherwise, formats the response using appropriate mapper. @param response resource's response. This can be - `None`, - django's `HttpResponse` - drest's `Response` - dictionary - plaintext """ if isinstance(response, HttpResponse): res = response elif self.mapper: res = self.mapper.format(response) else: res = datamapper.format(request, response, self.default_mapper) # data is now formatted, let's check if the status_code is set if res.status_code is 0: res.status_code = 200 return res