From c483c45f34e2a38a7387c5e423d92db3a1311117 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rodrigues?= Date: Wed, 30 Jan 2019 15:58:05 -0200 Subject: [PATCH] =?UTF-8?q?Tratar=20mandato=20sem=20data=20->=20mandatos?= =?UTF-8?q?=20interse=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/views.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/sapl/base/views.py b/sapl/base/views.py index d126561e5..3b2f79f3c 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1112,22 +1112,20 @@ class ListarAutoresDuplicadosView(PermissionRequiredMixin, ListView): def parlamentares_mandatos_intersecao(): intersecoes = [] + for parlamentar in Parlamentar.objects.all().order_by('nome_completo'): mandatos = parlamentar.mandato_set.all() - length = len(mandatos) - if mandatos and length > 1: - for i in range(0, length-1): - for j in range(i+1, length): - mandato = mandatos[i] - prox_mandato = mandatos[j] + combinacoes = itertools.combinations(mandatos, 2) + + for c in combinacoes: + if c[0].data_inicio_mandato and c[1].data_inicio_mandato: + if c[0].data_fim_mandato and c[1].data_fim_mandato: exists = intervalos_tem_intersecao( - mandato.data_inicio_mandato, - mandato.data_fim_mandato, - prox_mandato.data_inicio_mandato, - prox_mandato.data_fim_mandato) + c[0].data_inicio_mandato, c[0].data_fim_mandato, + c[1].data_inicio_mandato, c[1].data_fim_mandato) if exists: - intersecoes.append( - (parlamentar, mandato, prox_mandato)) + intersecoes.append((parlamentar, c[0], c[1])) + return intersecoes