Browse Source

Tratar mandato sem data -> mandatos interseção

pull/2454/head
João Rodrigues 7 years ago
committed by João Rodrigues
parent
commit
c483c45f34
  1. 22
      sapl/base/views.py

22
sapl/base/views.py

@ -1112,22 +1112,20 @@ class ListarAutoresDuplicadosView(PermissionRequiredMixin, ListView):
def parlamentares_mandatos_intersecao(): def parlamentares_mandatos_intersecao():
intersecoes = [] intersecoes = []
for parlamentar in Parlamentar.objects.all().order_by('nome_completo'): for parlamentar in Parlamentar.objects.all().order_by('nome_completo'):
mandatos = parlamentar.mandato_set.all() mandatos = parlamentar.mandato_set.all()
length = len(mandatos) combinacoes = itertools.combinations(mandatos, 2)
if mandatos and length > 1:
for i in range(0, length-1): for c in combinacoes:
for j in range(i+1, length): if c[0].data_inicio_mandato and c[1].data_inicio_mandato:
mandato = mandatos[i] if c[0].data_fim_mandato and c[1].data_fim_mandato:
prox_mandato = mandatos[j]
exists = intervalos_tem_intersecao( exists = intervalos_tem_intersecao(
mandato.data_inicio_mandato, c[0].data_inicio_mandato, c[0].data_fim_mandato,
mandato.data_fim_mandato, c[1].data_inicio_mandato, c[1].data_fim_mandato)
prox_mandato.data_inicio_mandato,
prox_mandato.data_fim_mandato)
if exists: if exists:
intersecoes.append( intersecoes.append((parlamentar, c[0], c[1]))
(parlamentar, mandato, prox_mandato))
return intersecoes return intersecoes

Loading…
Cancel
Save