diff --git a/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html b/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html index 6ab996675..a29b50f78 100644 --- a/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html +++ b/src-ui/src/app/components/dashboard/widgets/statistics-widget/statistics-widget.component.html @@ -1,6 +1,6 @@ -

Documents in inbox: {{statistics.documents_inbox}}

-

Total documents: {{statistics.documents_total}}

+

Documents in inbox: {{statistics?.documents_inbox}}

+

Total documents: {{statistics?.documents_total}}

diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py index 20eba6628..01e7210a5 100644 --- a/src/documents/tests/test_api.py +++ b/src/documents/tests/test_api.py @@ -442,6 +442,13 @@ def test_statistics(self): self.assertEqual(response.data['documents_total'], 3) self.assertEqual(response.data['documents_inbox'], 1) + def test_statistics_no_inbox_tag(self): + Document.objects.create(title="none1", checksum="A") + + response = self.client.get("/api/statistics/") + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data['documents_inbox'], None) + @mock.patch("documents.views.async_task") def test_upload(self, m): diff --git a/src/documents/views.py b/src/documents/views.py index 9d7b04508..68d6e3c77 100755 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -595,8 +595,14 @@ class StatisticsView(APIView): permission_classes = (IsAuthenticated,) def get(self, request, format=None): - return Response({ - 'documents_total': Document.objects.all().count(), - 'documents_inbox': Document.objects.filter( + documents_total = Document.objects.all().count() + if Tag.objects.filter(is_inbox_tag=True).exists(): + documents_inbox = Document.objects.filter( tags__is_inbox_tag=True).distinct().count() + else: + documents_inbox = None + + return Response({ + 'documents_total': documents_total, + 'documents_inbox': documents_inbox, })