From ff97492e63b7ef98b77e62d6d8aded20665a7132 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 31 May 2017 13:28:44 -0300 Subject: [PATCH] =?UTF-8?q?Otimiza=C3=A7=C3=A3o=20no=20c=C3=B3digo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/sessao/views.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 19923caca..1672d9ea5 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -124,6 +124,16 @@ def abrir_votacao_ordem_view(request, pk, spk): reverse('sapl.sessao:ordemdia_list', kwargs={'pk': spk})) +def put_link_materia(context): + for i, row in enumerate(context['rows']): + materia = context['object_list'][i].materia + url_materia = reverse('sapl.materia:materialegislativa_detail', + kwargs={'pk': materia.id}) + + context['rows'][i][1] = (row[1][0], url_materia) + return context + + class MateriaOrdemDiaCrud(MasterDetailCrud): model = OrdemDia parent_field = 'sessao_plenaria' @@ -166,19 +176,13 @@ class MateriaOrdemDiaCrud(MasterDetailCrud): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - for i in range(len(context['rows'])): - materia = context['object_list'][i].materia - url_materia = reverse('sapl.materia:materialegislativa_detail', - kwargs={'pk': materia.id}) - context['rows'][i][1] = (context['rows'][i][1][0], url_materia) - return context + return put_link_materia(context) def get_rows(self, object_list): for obj in object_list: exist_resultado = obj.registrovotacao_set.filter( - materia=obj.materia - ).exists() + materia=obj.materia).exists() if not exist_resultado: if obj.votacao_aberta: url = '' @@ -292,13 +296,8 @@ class ExpedienteMateriaCrud(MasterDetailCrud): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - for i in range(len(context['rows'])): - materia = context['object_list'][i].materia - url_materia = reverse('sapl.materia:materialegislativa_detail', - kwargs={'pk': materia.id}) - context['rows'][i][1] = (context['rows'][i][1][0], url_materia) - return context + return put_link_materia(context) def get_rows(self, object_list): for obj in object_list: