Coverage for apis_core/core/views.py: 67%
15 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
1import json
3from drf_spectacular.utils import OpenApiParameter, extend_schema, inline_serializer
4from rest_framework.permissions import IsAuthenticated
5from rest_framework.response import Response
6from rest_framework.views import APIView
8from apis_core.utils.helpers import datadump_serializer
11class Dumpdata(APIView):
12 """
13 provide an API endpoint that outputs the datadump of an APIS installation
15 this is a bit of a hack, becaus we first use the Django JSON serializer to
16 serialize the data using natural keys, then we use json.loads to so we can
17 output it as an API reponse.
18 so basically: serialize -> deserialize -> serialize
19 """
21 permission_classes = [IsAuthenticated]
23 @extend_schema(
24 parameters=[OpenApiParameter(name="app_labels", type=str, many=True)],
25 responses={200: inline_serializer(name="DumpDataResponse", fields={})},
26 )
27 def get(self, request, *args, **kwargs):
28 params = request.query_params.dict()
29 app_labels = params.pop("app_labels", [])
30 if app_labels:
31 app_labels = app_labels.split(",")
32 return Response(json.loads(datadump_serializer(app_labels, "json")))