Browse Source

Update progress method

pull/10/head
Hironsan 6 years ago
parent
commit
9106aa51fd
3 changed files with 16 additions and 7 deletions
  1. BIN
      app/db.sqlite3
  2. 2
      app/server/api.py
  3. 21
      app/server/models.py

BIN
app/db.sqlite3

2
app/server/api.py

@ -26,7 +26,7 @@ class ProjectViewSet(viewsets.ModelViewSet):
@action(methods=['get'], detail=True) @action(methods=['get'], detail=True)
def progress(self, request, pk=None): def progress(self, request, pk=None):
project = self.get_object() project = self.get_object()
return Response(project.get_progress())
return Response(project.get_progress(self.request.user))
class LabelList(generics.ListCreateAPIView): class LabelList(generics.ListCreateAPIView):

21
app/server/models.py

@ -31,8 +31,8 @@ class Project(models.Model):
def is_type_of(self, project_type): def is_type_of(self, project_type):
return project_type == 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() total = self.documents.count()
remaining = docs.count() remaining = docs.count()
return {'total': total, 'remaining': remaining} return {'total': total, 'remaining': remaining}
@ -60,14 +60,23 @@ class Project(models.Model):
return template_name return template_name
def get_documents(self, is_null=True):
def get_documents(self, is_null=True, user=None):
docs = self.documents.all() docs = self.documents.all()
if self.is_type_of(Project.DOCUMENT_CLASSIFICATION): 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): 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): 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: else:
raise ValueError('Invalid project_type') raise ValueError('Invalid project_type')

Loading…
Cancel
Save