From a19c82e211786c326964cdd973e00eeaf468f7bf Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Tue, 17 Nov 2020 21:18:54 -0300 Subject: [PATCH] =?UTF-8?q?HOT-FIX:=20endpoint=20de=20proposi=C3=A7=C3=B5e?= =?UTF-8?q?s=20por=20parlamentar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit em caso de uso do query params get_all=true o serializer utilizado era o da viewset do action, além disso, foi adicionado o filterset correspondente ao endpoit para que query params funcionem no endpoint. --- sapl/api/views.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/sapl/api/views.py b/sapl/api/views.py index 05893ad00..0aa9a5d3d 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -374,24 +374,32 @@ class _ParlamentarViewSet: # recupera proposições enviadas e incorporadas do parlamentar # deve coincidir com # /parlamentar/{pk}/proposicao - content_type = ContentType.objects.get_for_model(Parlamentar) - qs = Proposicao.objects.filter( + # viewset proposicao + api_proposicao = SaplApiViewSetConstrutor.get_class_for_model( + Proposicao + ) + + self.serializer_class = api_proposicao.serializer_class + self.filter_class = api_proposicao.filter_class + self.queryset = Proposicao.objects.all() + + qs = self.filter_queryset(self.get_queryset()) + + qs = qs.filter( data_envio__isnull=False, data_recebimento__isnull=False, cancelado=False, autor__object_id=kwargs['pk'], - autor__content_type=content_type + autor__content_type=ContentType.objects.get_for_model(Parlamentar) ) page = self.paginate_queryset(qs) - if page is not None: - serializer = SaplApiViewSetConstrutor.get_class_for_model( - Proposicao).serializer_class(page, many=True) - return self.get_paginated_response(serializer.data) + data = self.serializer_class( + page if page is not None else qs, many=True).data - serializer = self.get_serializer(page, many=True) - return Response(serializer.data) + return self.get_paginated_response( + data) if page is not None else Response(data) @action(detail=True) def parlamentares_by_legislatura(self, request, *args, **kwargs):