I created a custom APIView for creating reports for specific collabarators .
When I tried to add this api view to swagger and make post request from there it gives me
TypeError: ‘NoneType’ object is not iterable, but when I post through the django endpoint it works fine. I added print to check what might go wrong, and noticed that data doesn’t get “collabarators” field value list.
class ReportView(APIView):
permission_classes = [IsAuthenticated]
def get(self, *args, **kwargs):
tasks = ProjectTask.objects.all().exclude(Q(task_status__in=[0, 1, 2]) | Q(priority__in=[0]))
# print(tasks)
report = get_report_productivity(tasks)
return Response({"report":report}, 200)
@swagger_auto_schema(
request_body=openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'collaborators': openapi.Schema(
type=openapi.TYPE_ARRAY,
items=openapi.Items(type=openapi.TYPE_INTEGER)
),
},
required=['collaborators']
),
responses={202: openapi.Response('Response description', openapi.Schema(
type=openapi.TYPE_OBJECT,
properties={
'report': openapi.Schema(
type=openapi.TYPE_ARRAY,
items=openapi.Schema(type=openapi.TYPE_OBJECT)
)
}
))}
)
def post(self, request, *args, **kwargs):
data = request.data.get('collabarators')
print(type(data))
print(request.data.get('collabarators'))
print(request.data)
print(data)
if data is None:
return Response({"ok":"ok"}, 202)
# print(data)
# print(type(data))
# queryset = ProjectTask.objects.filter(executer__id__in=data)
# print(data)
# print(type(data))
# return Response({"ok":"ok"}, 202)
queryset = ProjectTask.objects.none()
for i in data:
queryset |= ProjectTask.objects.filter(executer__id=i).exclude(Q(task_status__in=[0, 1, 2]) | Q(priority__in=[0]))
report = get_report_productivity(queryset)
return Response({"report":report}, 202)
