@@ -326,39 +326,25 @@ class DetectionListViewSet(BaseViewSetMixin[Detection]):
326326 queryset = Detection .objects
327327 pagination_class = CachedCountLimitOffsetPagination
328328
329- def list (self , request , * args , ** kwargs ):
329+ def get_filtered_queryset (self ):
330330 queryset = self .filter_queryset (self .get_queryset ())
331331
332- page = self .paginate_queryset (queryset )
333-
334- if page is not None :
335- serializer = self .get_serializer (page , many = True )
336- return self .get_paginated_response (serializer .data )
337-
338- serializer = self .get_serializer (queryset , many = True )
339-
340- return Response (serializer .data )
341-
342- @action (methods = ["get" ], detail = False , url_path = "download" )
343- def download (self , request ):
344- params_serializer = DownloadParamsSerializer (data = request .GET )
345- params_serializer .is_valid (raise_exception = True )
332+ if self .action == "download" :
333+ queryset = get_list_values_list (
334+ queryset ,
335+ "detection_object__id" ,
336+ "detection_object__uuid" ,
337+ "detection_object__commune__name" ,
338+ "detection_object__object_type__name" ,
339+ "detection_object__parcel__section" ,
340+ "detection_object__parcel__num_parcel" ,
341+ "score" ,
342+ "detection_source" ,
343+ "detection_data__detection_control_status" ,
344+ "detection_data__detection_prescription_status" ,
345+ "detection_data__detection_validation_status" ,
346+ )
346347
347- queryset = self .filter_queryset (self .get_queryset ())
348- queryset = get_list_values_list (
349- queryset ,
350- "detection_object__id" ,
351- "detection_object__uuid" ,
352- "detection_object__commune__name" ,
353- "detection_object__object_type__name" ,
354- "detection_object__parcel__section" ,
355- "detection_object__parcel__num_parcel" ,
356- "score" ,
357- "detection_source" ,
358- "detection_data__detection_control_status" ,
359- "detection_data__detection_prescription_status" ,
360- "detection_data__detection_validation_status" ,
361- )
362348 tile_sets_subquery = (
363349 DetectionObject .objects .filter (id = OuterRef ("detection_object__id" ))
364350 .annotate (
@@ -385,9 +371,32 @@ def download(self, request):
385371
386372 queryset = queryset .annotate (
387373 tile_sets = Subquery (tile_sets_subquery ),
388- custom_zones = Subquery (custom_zones_subquery ),
374+ geo_custom_zones = Subquery (custom_zones_subquery ),
389375 geometry_center = Centroid ("geometry" ),
390376 )
377+
378+ return queryset
379+
380+ def list (self , request , * args , ** kwargs ):
381+ queryset = self .get_filtered_queryset ()
382+
383+ page = self .paginate_queryset (queryset )
384+
385+ if page is not None :
386+ serializer = self .get_serializer (page , many = True )
387+ return self .get_paginated_response (serializer .data )
388+
389+ serializer = self .get_serializer (queryset , many = True )
390+
391+ return Response (serializer .data )
392+
393+ @action (methods = ["get" ], detail = False , url_path = "download" )
394+ def download (self , request ):
395+ params_serializer = DownloadParamsSerializer (data = request .GET )
396+ params_serializer .is_valid (raise_exception = True )
397+
398+ queryset = self .get_filtered_queryset ()
399+
391400 # safety to not consume too much memory and kill the api
392401 queryset = queryset [:DOWNLOAD_LIMIT_ROWS ]
393402
0 commit comments