Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
only show inbox statistics if inbox tags are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaswinkler committed Feb 15, 2021
1 parent 3f03d51 commit cb308fa
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<app-widget-frame title="Statistics" i18n-title>
<ng-container content>
<p class="card-text" i18n>Documents in inbox: {{statistics.documents_inbox}}</p>
<p class="card-text" i18n>Total documents: {{statistics.documents_total}}</p>
<p class="card-text" i18n *ngIf="statistics?.documents_inbox != null">Documents in inbox: {{statistics?.documents_inbox}}</p>
<p class="card-text" i18n>Total documents: {{statistics?.documents_total}}</p>
</ng-container>
</app-widget-frame>
7 changes: 7 additions & 0 deletions src/documents/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down
12 changes: 9 additions & 3 deletions src/documents/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})

0 comments on commit cb308fa

Please sign in to comment.