From 031c28ba13c75f2476109b4d590cf85e9eab7887 Mon Sep 17 00:00:00 2001 From: william Date: Thu, 29 Aug 2024 17:45:03 +1000 Subject: [PATCH] Update lab.py --- .../metadata-manager/app/viewsets/lab.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/workload/stateless/stacks/metadata-manager/app/viewsets/lab.py b/lib/workload/stateless/stacks/metadata-manager/app/viewsets/lab.py index e0670dfed..077fe3451 100644 --- a/lib/workload/stateless/stacks/metadata-manager/app/viewsets/lab.py +++ b/lib/workload/stateless/stacks/metadata-manager/app/viewsets/lab.py @@ -16,7 +16,7 @@ class SubjectViewSet(ReadOnlyModelViewSet): pagination_class = StandardResultsSetPagination filter_backends = [filters.OrderingFilter, filters.SearchFilter] ordering_fields = "__all__" - ordering = ["-subject_id"] + ordering = ["-orcabus_id"] search_fields = Subject.get_base_fields() queryset = Subject.objects.none() @@ -33,7 +33,7 @@ def get_queryset(self): responses={200: SubjectFullSerializer(many=True)}, parameters=[ SubjectSerializer, - OpenApiParameter(name='libraryId', + OpenApiParameter(name='library_id', description='Filter the subjects that has the given library_id in ' 'the Library model.', required=False, @@ -43,10 +43,12 @@ def get_queryset(self): @action(detail=False, methods=['get'], url_path='full') def get_full_model_set(self, request): query_params = self.request.query_params.copy() - qs = Subject.objects.prefetch_related("specimen_set__library_set").all().order_by("-subject_id") - # Allow filtering by libraryId - library_id = query_params.get("libraryId", None) + ordering = query_params.get("ordering", '-orcabus_id') + qs = Subject.objects.prefetch_related("specimen_set__library_set").all().order_by(ordering) + + # Allow filtering by library_id + library_id = query_params.get("library_id", None) if library_id: query_params.pop("library_id") qs = qs.filter(specimen__library__library_id=library_id) @@ -74,7 +76,7 @@ class SpecimenViewSet(ReadOnlyModelViewSet): pagination_class = StandardResultsSetPagination filter_backends = [filters.OrderingFilter, filters.SearchFilter] ordering_fields = "__all__" - ordering = ["-specimen_id"] + ordering = ["-orcabus_id"] search_fields = Specimen.get_base_fields() queryset = Specimen.objects.none() @@ -94,7 +96,7 @@ class LibraryViewSet(ReadOnlyModelViewSet): pagination_class = StandardResultsSetPagination filter_backends = [filters.OrderingFilter, filters.SearchFilter] ordering_fields = "__all__" - ordering = ["-library_id"] + ordering = ["-orcabus_id"] search_fields = Library.get_base_fields() queryset = Library.objects.none() @@ -113,7 +115,10 @@ def get_queryset(self): ) @action(detail=False, methods=['get'], url_path='full') def get_full_model_set(self, request): - qs = Library.objects.select_related("specimen__subject").all().order_by("-library_id") + query_params = self.request.query_params.copy() + + ordering = query_params.get("ordering", '-orcabus_id') + qs = Library.objects.select_related("specimen__subject").all().order_by(ordering) # Allow filtering by the keys inside the library model qs = Library.objects.get_model_fields_query(qs, **self.request.query_params)