From ce34bacc42680321a8f3f590d3895fa360513ca3 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Tue, 18 Jan 2022 07:12:40 +0900 Subject: [PATCH] Remove DocumentAPI --- backend/api/filters.py | 29 ----------------------------- backend/api/urls.py | 11 ----------- backend/api/views/example.py | 14 +------------- 3 files changed, 1 insertion(+), 53 deletions(-) diff --git a/backend/api/filters.py b/backend/api/filters.py index cdd02b1e..e035fc65 100644 --- a/backend/api/filters.py +++ b/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') diff --git a/backend/api/urls.py b/backend/api/urls.py index eef0a90e..47dc494a 100644 --- a/backend/api/urls.py +++ b/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/', - view=example.DocumentDetail.as_view(), - name='doc_detail' - ), path( route='approval/', view=annotation.ApprovalAPI.as_view(), diff --git a/backend/api/views/example.py b/backend/api/views/example.py index 8568626f..54c4c669 100644 --- a/backend/api/views/example.py +++ b/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]