Browse Source

Merge pull request #1638 from doccano/enhancement/deleteDocumentAPI

Remove DocumentAPI
pull/1641/head
Hiroki Nakayama 2 years ago
committed by GitHub
parent
commit
93d4349f29
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 1 additions and 53 deletions
  1. 29
      backend/api/filters.py
  2. 11
      backend/api/urls.py
  3. 14
      backend/api/views/example.py

29
backend/api/filters.py

@ -4,35 +4,6 @@ from django_filters.rest_framework import BooleanFilter, FilterSet
from .models import Example
class DocumentFilter(FilterSet):
spans__isnull = BooleanFilter(field_name='spans', method='filter_annotations')
categories__isnull = BooleanFilter(field_name='categories', method='filter_annotations')
texts__isnull = BooleanFilter(field_name='texts', method='filter_annotations')
def filter_annotations(self, queryset, field_name, value):
queryset = queryset.annotate(num_annotations=Count(
expression=field_name,
filter=Q(**{f"{field_name}__user": self.request.user}) | Q(project__collaborative_annotation=True)
)
)
should_have_annotations = not value
if should_have_annotations:
queryset = queryset.filter(num_annotations__gte=1)
else:
queryset = queryset.filter(num_annotations__lte=0)
return queryset
class Meta:
model = Example
fields = (
'project', 'text', 'created_at', 'updated_at',
'categories__label__id', 'spans__label__id',
'categories__isnull', 'spans__isnull', 'texts__isnull'
)
class ExampleFilter(FilterSet):
confirmed = BooleanFilter(field_name='states', method='filter_by_state')

11
backend/api/urls.py

@ -96,17 +96,6 @@ urlpatterns_project = [
view=relation.RelationDetail.as_view(),
name='annotation_relation_detail'
),
# Todo: remove.
path(
route='docs',
view=example.DocumentList.as_view(),
name='doc_list'
),
path(
route='docs/<int:doc_id>',
view=example.DocumentDetail.as_view(),
name='doc_detail'
),
path(
route='approval/<int:example_id>',
view=annotation.ApprovalAPI.as_view(),

14
backend/api/views/example.py

@ -9,7 +9,7 @@ from rest_framework.response import Response
from members.permissions import IsInProjectReadOnlyOrAdmin
from ..filters import DocumentFilter, ExampleFilter
from ..filters import ExampleFilter
from ..models import Example, Project
from ..serializers import ExampleSerializer
@ -56,15 +56,3 @@ class ExampleDetail(generics.RetrieveUpdateDestroyAPIView):
serializer_class = ExampleSerializer
lookup_url_kwarg = 'example_id'
permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]
class DocumentList(ExampleList):
search_fields = ('text',)
filter_class = DocumentFilter
class DocumentDetail(generics.RetrieveUpdateDestroyAPIView):
queryset = Example.objects.all()
serializer_class = ExampleSerializer
lookup_url_kwarg = 'doc_id'
permission_classes = [IsAuthenticated & IsInProjectReadOnlyOrAdmin]
Loading…
Cancel
Save