From 1867259d5e6cf318e5b859b2f4dd32e2f8dca33e Mon Sep 17 00:00:00 2001 From: TannedCung Date: Wed, 4 Dec 2024 17:07:13 +0700 Subject: [PATCH] Add: bad_reason filter --- cope2n-api/fwd_api/api/accuracy_view.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cope2n-api/fwd_api/api/accuracy_view.py b/cope2n-api/fwd_api/api/accuracy_view.py index 3fd2ed1..9968dae 100755 --- a/cope2n-api/fwd_api/api/accuracy_view.py +++ b/cope2n-api/fwd_api/api/accuracy_view.py @@ -142,6 +142,13 @@ class AccuracyViewSet(viewsets.ViewSet): enum=list(settings.DOC_TYPES), required=False ), + OpenApiParameter( + name='bad_reason', + location=OpenApiParameter.QUERY, + description='Filter by bad reason', + type=OpenApiTypes.STR, + required=False + ), ], responses=None, tags=['Accuracy'] ) @@ -163,6 +170,7 @@ class AccuracyViewSet(viewsets.ViewSet): feedback_result = request.GET.get('feedback_result', None) reviewed_result = request.GET.get('reviewed_result', None) doc_type = request.GET.get('doc_type', None) + bad_reason = request.GET.get('bad_reason', None) base_query = Q(status=200) if start_date_str or end_date_str: @@ -242,6 +250,12 @@ class AccuracyViewSet(viewsets.ViewSet): base_query &= Q(raw_accuracy__lt=( max_accuracy/100)) | Q(raw_accuracy__isnull=True) + if bad_reason: + bad_reason_subquery = SubscriptionRequestFile.objects.filter( + reason__icontains=bad_reason + ).values_list('request_id', flat=True) + base_query &= Q(id__in=bad_reason_subquery) + subscription_requests = SubscriptionRequest.objects.filter( base_query).order_by('created_at')