Beispiel #1
0
    def list(self, request, *args, **kwargs):
        params = request.query_params

        if params.get('chemical_analyses_filters') == 'True':
            chem_qs = ChemicalAnalysis.objects.all()
            chem_qs = chemical_analyses_qs_optimizer(params, chem_qs)
            chem_ids = (chemical_analysis_query(request.user, params,
                                                chem_qs).values_list('id'))
            qs = (Sample.objects.filter(
                subsamples__chemical_analyses__id__in=chem_ids))
        else:
            qs = self.get_queryset().distinct()
            try:
                qs = sample_query(request.user, params, qs)
            except ValueError as err:
                return Response(data={'error': err.args}, status=400)

        qs = sample_qs_optimizer(params, qs)

        page = self.paginate_queryset(qs)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(qs, many=True)
        return Response(serializer.data)
Beispiel #2
0
    def list(self, request, *args, **kwargs):
        params = request.query_params

        if params.get('chemical_analyses_filters') == 'True':
            chem_qs = ChemicalAnalysis.objects.all()
            chem_qs = chemical_analyses_qs_optimizer(params, chem_qs)
            chem_ids = (chemical_analysis_query(request.user, params, chem_qs)
                        .values_list('id'))
            qs = (Sample
                  .objects
                  .filter(subsamples__chemical_analyses__id__in=chem_ids))
        else:
            qs = self.get_queryset().distinct()
            try:
                qs = sample_query(request.user, params, qs)
            except ValueError as err:
                return Response(
                    data={'error': err.args},
                    status=400
                )

        qs = sample_qs_optimizer(params, qs)

        page = self.paginate_queryset(qs)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(qs, many=True)
        return Response(serializer.data)
Beispiel #3
0
    def list(self, request, *args, **kwargs):
        params = request.query_params

        if params.get('sample_filters') == 'True':
            sample_qs = Sample.objects.all()
            sample_qs = sample_qs_optimizer(params, sample_qs)
            sample_ids = sample_query(request.user, params,
                                      sample_qs).values_list('id')
            qs = ChemicalAnalysis.objects.filter(
                subsample__sample_id__in=sample_ids)
        else:
            qs = self.get_queryset().distinct()
            qs = chemical_analysis_query(request.user, params, qs)

        qs = chemical_analyses_qs_optimizer(params, qs)

        page = self.paginate_queryset(qs)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(qs, many=True)
        return Response(serializer.data)
Beispiel #4
0
    def list(self, request, *args, **kwargs):
        params = request.query_params

        if params.get('sample_filters') == 'True':
            sample_qs = Sample.objects.all()
            sample_qs = sample_qs_optimizer(params, sample_qs)
            sample_ids = sample_query(request.user,
                                      params,
                                      sample_qs).values_list('id')
            qs = ChemicalAnalysis.objects.filter(
                subsample__sample_id__in=sample_ids)
        else:
            qs = self.get_queryset().distinct()
            qs = chemical_analysis_query(request.user, params, qs)

        qs = chemical_analyses_qs_optimizer(params, qs)

        page = self.paginate_queryset(qs)
        if page is not None:
            serializer = self.get_serializer(page, many=True)
            return self.get_paginated_response(serializer.data)

        serializer = self.get_serializer(qs, many=True)
        return Response(serializer.data)