fix pendingactions count

This commit is contained in:
wh1te909
2021-03-03 11:07:20 +00:00
parent 0ef4e9a5c3
commit 0453d81e7a
2 changed files with 12 additions and 4 deletions

View File

@@ -218,8 +218,8 @@ class TestAuditViews(TacticalTestCase):
r = self.client.patch(url, data, format="json")
self.assertEqual(r.status_code, 200)
self.assertEqual(len(r.data["actions"]), 12) # type: ignore
self.assertEqual(r.data["completed_count"], 26) # type: ignore
self.assertEqual(r.data["total"], 26) # type: ignore
self.assertEqual(r.data["completed_count"], 12) # type: ignore
self.assertEqual(r.data["total"], 12) # type: ignore
self.check_not_authenticated("patch", url)

View File

@@ -113,16 +113,24 @@ class PendingActions(APIView):
actions = PendingAction.objects.filter(
agent__pk=request.data["agentPK"], status=status_filter
)
total = PendingAction.objects.filter(
agent__pk=request.data["agentPK"]
).count()
completed = PendingAction.objects.filter(
agent__pk=request.data["agentPK"], status="completed"
).count()
else:
actions = PendingAction.objects.filter(status=status_filter).select_related(
"agent"
)
total = PendingAction.objects.count()
completed = PendingAction.objects.filter(status="completed").count()
ret = {
"actions": PendingActionSerializer(actions, many=True).data,
"completed_count": PendingAction.objects.filter(status="completed").count(),
"total": PendingAction.objects.count(),
"completed_count": completed,
"total": total,
}
return Response(ret)