From 9106aa51fda317cbc11a7cf563ccbd759ab6e717 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 13 Aug 2018 14:48:25 +0900 Subject: [PATCH] Update progress method --- app/db.sqlite3 | Bin 241664 -> 241664 bytes app/server/api.py | 2 +- app/server/models.py | 21 +++++++++++++++------ 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/db.sqlite3 b/app/db.sqlite3 index 10fc26ffdd8240e8be386e11634646d0610ea450..644300ab7174b7d1e019b7b4b7b2a52e04364f0d 100644 GIT binary patch delta 627 zcmY+BPfHt76vf}4c}d=LGG`K{mKsYIT?hrUkkVxZzknONjWpB1-nS^os8Aa;xKpS_s+Rc!#d-! zLi5TRR|0=m9k5grph)S)NCWTzo+NLu15kx93iEHdx+CFy5z$9pJWo6 gUo@TKl5eTxED77{5OJ@gr)|Y>h@pRe+tGIUFG^&Q&Hw-a delta 585 zcmY*WJxe1|6n*!-H?#A#b0#sUtbihRksw8 z4m~cOxC3<2dCMJ@0|GVoujsn`mFmx{6dC8?{9MAta&a(8R&vQp8;9F#F9@gOk71H;#t*2*Pqjsh!2 z4;j5@^c-=4GU%HmFx>^iTobr|RsuRA~+0Uhpc%eh%e^ac93Ft1aSf03T7sR@_ovZ}@J*I!fa F(jy62ip~H4 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')