diff --git a/frontend/src/__apps/parlamentar/main.js b/frontend/src/__apps/parlamentar/main.js index 602bd63b9..958569392 100644 --- a/frontend/src/__apps/parlamentar/main.js +++ b/frontend/src/__apps/parlamentar/main.js @@ -38,7 +38,7 @@ const v = new Vue({ // eslint-disable-line methods: { getParlamentares (event) { if (this.legislatura_selecionada || this.legislatura_selecionada.toString() === '0') { - axios.get('/api/parlamentares/parlamentar/' + this.legislatura_selecionada + '/parlamentares_by_legislatura/') + axios.get('/api/parlamentares/legislatura/' + this.legislatura_selecionada + '/parlamentares/?get_all=true') .then(response => { this.parlamentares = response.data this.visible_parlamentares = this.parlamentares diff --git a/sapl/api/views.py b/sapl/api/views.py index 2bbf25215..eb6451970 100644 --- a/sapl/api/views.py +++ b/sapl/api/views.py @@ -277,7 +277,7 @@ class wrapper_queryset_response_for_drf_action(object): qs = cls(instance_view, *args, **kwargs) page = iv.paginate_queryset(qs) - data = iv.serializer_class( + data = iv.get_serializer( page if page is not None else qs, many=True).data return iv.get_paginated_response( @@ -412,27 +412,52 @@ class _ParlamentarViewSet: @wrapper_queryset_response_for_drf_action(model=Proposicao) def get_proposicoes(self, **kwargs): - qs = self.get_queryset() - - qs = qs.filter( + return self.get_queryset().filter( data_envio__isnull=False, data_recebimento__isnull=False, cancelado=False, autor__object_id=kwargs['pk'], autor__content_type=ContentType.objects.get_for_model(Parlamentar) ) - return qs + + @action(detail=False, methods=['GET']) + def search_parlamentares(self, request, *args, **kwargs): + nome = request.query_params.get('nome_parlamentar', '') + parlamentares = Parlamentar.objects.filter( + nome_parlamentar__icontains=nome) + serializer_class = ParlamentarResumeSerializer( + parlamentares, many=True, context={'request': request}) + return Response(serializer_class.data) + + +@customize(Legislatura) +class _LegislaturaViewSet: @action(detail=True) - def parlamentares_by_legislatura(self, request, *args, **kwargs): - """ - Pega lista de parlamentares pelo id da legislatura. - """ + def parlamentares(self, request, *args, **kwargs): + + def get_serializer_context(): + return { + 'request': self.request, 'legislatura': kwargs['pk'] + } + + def get_serializer_class(): + return ParlamentarResumeSerializer + + self.get_serializer_context = get_serializer_context + self.get_serializer_class = get_serializer_class + + return self.get_parlamentares() + + @wrapper_queryset_response_for_drf_action(model=Parlamentar) + def get_parlamentares(self): + try: - legislatura = Legislatura.objects.get(pk=kwargs['pk']) + legislatura = Legislatura.objects.get(pk=self.kwargs['pk']) except ObjectDoesNotExist: return Response("") - data_atual = timezone.now().date() + + data_atual = timezone.localdate() filter_params = { 'legislatura': legislatura, @@ -442,21 +467,11 @@ class _ParlamentarViewSet: mandatos = Mandato.objects.filter( **filter_params).order_by('-data_inicio_mandato') - parlamentares = Parlamentar.objects.filter( + + parlamentares = self.get_queryset().filter( mandato__in=mandatos).distinct() - serializer_class = ParlamentarResumeSerializer(parlamentares, many=True, context={ - 'request': request, 'legislatura': kwargs['pk'] - }) - return Response(serializer_class.data) - @action(detail=False, methods=['GET']) - def search_parlamentares(self, request, *args, **kwargs): - nome = request.query_params.get('nome_parlamentar', '') - parlamentares = Parlamentar.objects.filter( - nome_parlamentar__icontains=nome) - serializer_class = ParlamentarResumeSerializer( - parlamentares, many=True, context={'request': request}) - return Response(serializer_class.data) + return parlamentares @customize(Proposicao) @@ -647,11 +662,11 @@ class _SessaoPlenariaViewSet: @action(detail=True) def expedientes(self, request, *args, **kwargs): - return self.get_expedientes(**kwargs) + return self.get_expedientes() @wrapper_queryset_response_for_drf_action(model=ExpedienteSessao) - def get_expedientes(self, **kwargs): - return self.get_queryset().filter(sessao_plenaria_id=kwargs['pk']) + def get_expedientes(self): + return self.get_queryset().filter(sessao_plenaria_id=self.kwargs['pk']) @customize(NormaJuridica)