def _create_response(self, result: Any): if isinstance(result, HttpResponse): return result if self.response_model is None: return Response(result) result = self.response_model(response=result).dict()["response"] return Response(result)
def _create_response(self, result: Any): if isinstance(result, HttpResponse): return result if self.response_model is None: return Response(result) resp_object = ResponseObject(result) # ^ we need object because getter_dict seems work only with from_orm result = self.response_model.from_orm(resp_object).dict()["response"] return Response(result)
def _run_authentication(self, request): for callback in self.auth_callbacks: result = callback(request) if result is not None: request.auth = result return return Response({"detail": "Unauthorized"}, status=401)
def run(self, request, **kw): error = self._run_checks(request) if error: return error values, errors = self._get_values(request, kw) if errors: return Response({"detail": errors}, status=422) result = self.view_func(request, **values) return self._create_response(result)
def run(self, request, **kw): unauthorized = self._run_authentication(request) if unauthorized: return unauthorized values, errors = self._get_values(request, kw) if errors: return Response({"detail": errors}, status=422) result = self.view_func(request, **values) return self._create_response(result)
def _create_response(self, result: Any): if isinstance(result, HttpResponse): return result if self.response_model is None: return Response(result) status = 200 response_model = self.response_model if isinstance(result, tuple) and len(result) == 2: status = result[0] result = result[1] if isinstance(response_model, dict): if status not in response_model.keys(): raise ConfigError(f"Schema for status {status} is not set in response") response_model = response_model[status] resp_object = ResponseObject(result) # ^ we need object because getter_dict seems work only with from_orm result = response_model.from_orm(resp_object).dict()["response"] return Response(result, status=status)
def openapi_json(request, api: "NinjaAPI"): schema = api.get_openapi_schema() return Response(schema)