mirror of https://github.com/interlegis/sapl.git
committed by
GitHub
22 changed files with 684 additions and 129 deletions
@ -0,0 +1,35 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.20 on 2019-03-14 18:32 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('protocoloadm', '0017_merge_20190121_1552'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.CreateModel( |
|||
name='Anexado', |
|||
fields=[ |
|||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), |
|||
('data_anexacao', models.DateField(verbose_name='Data Anexação')), |
|||
('data_desanexacao', models.DateField(blank=True, null=True, verbose_name='Data Desanexação')), |
|||
('documento_anexado', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documento_anexado_set', to='protocoloadm.DocumentoAdministrativo', verbose_name='Documento Anexado')), |
|||
('documento_principal', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='documento_principal_set', to='protocoloadm.DocumentoAdministrativo', verbose_name='Documento Principal')), |
|||
], |
|||
options={ |
|||
'verbose_name': 'Anexado', |
|||
'verbose_name_plural': 'Anexados', |
|||
}, |
|||
), |
|||
migrations.AddField( |
|||
model_name='documentoadministrativo', |
|||
name='anexados', |
|||
field=models.ManyToManyField(blank=True, related_name='anexo_de', through='protocoloadm.Anexado', to='protocoloadm.DocumentoAdministrativo'), |
|||
), |
|||
] |
|||
@ -1,5 +1,5 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.20 on 2019-04-10 11:36 |
|||
# Generated by Django 1.11.20 on 2019-04-12 14:06 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
@ -0,0 +1,33 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.20 on 2019-04-15 16:24 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.conf import settings |
|||
from django.db import migrations, models |
|||
import django.db.models.deletion |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), |
|||
('sessao', '0036_auto_20190412_1106'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AddField( |
|||
model_name='registrovotacao', |
|||
name='data_hora', |
|||
field=models.DateTimeField(auto_now_add=True, null=True, verbose_name='Data/Hora'), |
|||
), |
|||
migrations.AddField( |
|||
model_name='registrovotacao', |
|||
name='ip', |
|||
field=models.CharField(blank=True, default='', max_length=30, verbose_name='IP'), |
|||
), |
|||
migrations.AddField( |
|||
model_name='registrovotacao', |
|||
name='user', |
|||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL), |
|||
), |
|||
] |
|||
@ -0,0 +1,13 @@ |
|||
{% extends "crud/list.html" %} |
|||
{% load i18n %} |
|||
{% load common_tags %} |
|||
|
|||
{% block more_buttons %} |
|||
|
|||
{% if perms|get_add_perm:view %} |
|||
<a href="{% url 'sapl.protocoloadm:anexado_em_lote' root_pk %}" class="btn btn-outline-primary"> |
|||
{% trans "Adicionar Anexado em Lote" %} |
|||
</a> |
|||
{% endif %} |
|||
|
|||
{% endblock more_buttons %} |
|||
@ -0,0 +1,84 @@ |
|||
from django.core.exceptions import ObjectDoesNotExist |
|||
from django.db.models import Count |
|||
from sapl.base.models import Autor |
|||
from sapl.parlamentares.models import Parlamentar |
|||
|
|||
|
|||
def pega_autores(): |
|||
return [[autor for autor in Autor.objects.filter(nome=nome)] |
|||
for nome in Autor.objects.values_list('nome', flat=True).annotate(qntd=Count('nome')).filter(qntd__gt=1)] |
|||
|
|||
|
|||
def pega_parlamentares_autores(): |
|||
parlamentares = [[parlamentar for parlamentar in Parlamentar.objects.filter(nome_parlamentar=nome_parlamentar)] |
|||
for nome_parlamentar in Parlamentar.objects.values_list('nome_parlamentar', flat=True) |
|||
.annotate(qntd=Count('nome_parlamentar')).filter(qntd__gt=1)] |
|||
|
|||
parlamentares_autores = [] |
|||
|
|||
for parlamentar in parlamentares: |
|||
parlamentar_autor = [] |
|||
for clone in parlamentar[1:]: |
|||
try: |
|||
autor_principal = Autor.objects.get(parlamentar_set=parlamentar[0]) |
|||
except ObjectDoesNotExist: |
|||
try: |
|||
autor_clonado = Autor.objects.get(parlamentar_set=clone) |
|||
except ObjectDoesNotExist: |
|||
pass |
|||
else: |
|||
autor_clonado.object_id = parlamentar[0].id |
|||
autor_clonado.save() |
|||
parlamentares_autores.append(autor_clonado) |
|||
else: |
|||
if len(parlamentar_autor) == 0: |
|||
parlamentar_autor.append(autor_principal) |
|||
|
|||
try: |
|||
autor_clonado = Autor.objects.get(parlamentar_set=clone) |
|||
except ObjectDoesNotExist: |
|||
pass |
|||
else: |
|||
parlamentar_autor.append(autor_clonado) |
|||
parlamentares_autores.extend(parlamentar_autor) |
|||
|
|||
return parlamentares_autores |
|||
|
|||
|
|||
def transfere_valeres(autores): |
|||
for autor in autores: |
|||
for clone in autor[1:]: |
|||
for autoria in clone.autoria_set.all(): |
|||
autoria.autor_id = autor[0] |
|||
autoria.save() |
|||
|
|||
for proposicao in clone.proposicao_set.all(): |
|||
proposicao.autor_id = autor[0] |
|||
proposicao.save() |
|||
|
|||
for autorianorma in clone.autorianorma_set.all(): |
|||
autorianorma.autor_id = autor[0] |
|||
autorianorma.save() |
|||
|
|||
for documentoadministrativo in clone.documentoadministrativo_set.all(): |
|||
documentoadministrativo.autor_id = autor[0] |
|||
documentoadministrativo.save() |
|||
|
|||
for protocolo in clone.protocolo_set.all(): |
|||
protocolo.autor_id = autor[0] |
|||
protocolo.save() |
|||
|
|||
clone.delete() |
|||
|
|||
|
|||
def main(): |
|||
autores = pega_autores() |
|||
parlamentares_autores = pega_parlamentares_autores() |
|||
|
|||
autores.append(parlamentares_autores) |
|||
|
|||
transfere_valeres(autores) |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
main() |
|||
Loading…
Reference in new issue