Browse Source

Remove is_labeled method from Example

pull/1650/head
Hironsan 2 years ago
parent
commit
72f3a7c74c
3 changed files with 2 additions and 26 deletions
  1. 11
      backend/api/models.py
  2. 8
      backend/auto_labeling/exceptions.py
  3. 9
      backend/auto_labeling/views.py

11
backend/api/models.py

@ -264,17 +264,6 @@ class Example(models.Model):
else:
return str(self.filename)
def is_labeled(self, is_collaborative, user):
if is_collaborative:
for model in Annotation.__subclasses__():
if model.objects.filter(example=self.id).exists():
return True
else:
for model in Annotation.__subclasses__():
if model.objects.filter(example=self.id, user=user).exists():
return True
return False
class Meta:
ordering = ['created_at']

8
backend/auto_labeling/exceptions.py

@ -1,10 +1,4 @@
from rest_framework import status
from rest_framework.exceptions import APIException, PermissionDenied, ValidationError
class AutoLabelingException(APIException):
status_code = status.HTTP_400_BAD_REQUEST
default_detail = 'Auto labeling not allowed for the document with labels.'
from rest_framework.exceptions import PermissionDenied, ValidationError
class AutoLabelingPermissionDenied(PermissionDenied):

9
backend/auto_labeling/views.py

@ -19,7 +19,7 @@ from rest_framework.views import APIView
from api.models import Example, Project
from members.permissions import IsInProjectOrAdmin, IsProjectAdmin
from .exceptions import (AutoLabelingException, AutoLabelingPermissionDenied,
from .exceptions import (AutoLabelingPermissionDenied,
AWSTokenError, SampleDataException,
TemplateMappingError, URLConnectionError)
from .models import AutoLabelingConfig
@ -196,14 +196,7 @@ class AutomatedDataLabeling(generics.CreateAPIView):
self.serializer_class = get_annotation_serializer(task=project.project_type)
return self.serializer_class
def cannot_annotate(self):
project = get_object_or_404(Project, pk=self.kwargs['project_id'])
example = get_object_or_404(Example, pk=self.kwargs['example_id'])
return example.is_labeled(project.collaborative_annotation, self.request.user)
def create(self, request, *args, **kwargs):
if self.cannot_annotate():
raise AutoLabelingException()
labels = self.extract()
labels = self.transform(labels)
serializer = self.get_serializer(data=labels, many=True)

Loading…
Cancel
Save