diff --git a/app/db.sqlite3 b/app/db.sqlite3 index 10fc26ff..644300ab 100644 Binary files a/app/db.sqlite3 and b/app/db.sqlite3 differ diff --git a/app/server/api.py b/app/server/api.py index bd14730e..3d2f64c0 100644 --- a/app/server/api.py +++ b/app/server/api.py @@ -26,7 +26,7 @@ class ProjectViewSet(viewsets.ModelViewSet): @action(methods=['get'], detail=True) def progress(self, request, pk=None): project = self.get_object() - return Response(project.get_progress()) + return Response(project.get_progress(self.request.user)) class LabelList(generics.ListCreateAPIView): diff --git a/app/server/models.py b/app/server/models.py index fc24ec38..2515932b 100644 --- a/app/server/models.py +++ b/app/server/models.py @@ -31,8 +31,8 @@ class Project(models.Model): def is_type_of(self, project_type): return project_type == self.project_type - def get_progress(self): - docs = self.get_documents(is_null=True) + def get_progress(self, user): + docs = self.get_documents(is_null=True, user=user) total = self.documents.count() remaining = docs.count() return {'total': total, 'remaining': remaining} @@ -60,14 +60,23 @@ class Project(models.Model): return template_name - def get_documents(self, is_null=True): + def get_documents(self, is_null=True, user=None): docs = self.documents.all() if self.is_type_of(Project.DOCUMENT_CLASSIFICATION): - docs = docs.filter(doc_annotations__isnull=is_null) + if user: + docs = docs.exclude(doc_annotations__user=user) + else: + docs = docs.filter(doc_annotations__isnull=is_null) elif self.is_type_of(Project.SEQUENCE_LABELING): - docs = docs.filter(seq_annotations__isnull=is_null) + if user: + docs = docs.exclude(seq_annotations__user=user) + else: + docs = docs.filter(seq_annotations__isnull=is_null) elif self.is_type_of(Project.Seq2seq): - docs = docs.filter(seq2seq_annotations__isnull=is_null) + if user: + docs = docs.exclude(seq2seq_annotations__user=user) + else: + docs = docs.filter(seq2seq_annotations__isnull=is_null) else: raise ValueError('Invalid project_type')