From 2281589e94bfb94f59bc967d0495c9f11ea73921 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 30 May 2017 14:09:24 -0300 Subject: [PATCH] Trata listagem de composicao inexistente --- sapl/comissoes/views.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index c7c7bd117..0b80245c5 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -54,9 +54,21 @@ class ComposicaoCrud(MasterDetailCrud): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - context['composicao_pk'] = context['composicao_list'].last( - ).pk if self.take_composicao_pk( - ) == 0 else self.take_composicao_pk() +# context['composicao_pk'] = context['composicao_list'].last( +# ).pk if self.take_composicao_pk( +# ) == 0 else self.take_composicao_pk() + + composicao_pk = self.take_composicao_pk() + + if composicao_pk == 0: + ultima_composicao = context['composicao_list'].last() + if ultima_composicao: + context['composicao_pk'] = ultima_composicao.pk + else: + context['composicao_pk'] = 0 + else: + context['composicao_pk'] = composicao_pk + context['participacao_set'] = Participacao.objects.filter( composicao__pk=context['composicao_pk'] ).order_by('parlamentar')