mirror of https://github.com/interlegis/sapl.git
committed by
GitHub
13 changed files with 260 additions and 22 deletions
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.20 on 2019-04-15 13:50 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('base', '0032_merge_20190219_0941'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='appconfig', |
|||
name='sequencia_numeracao', |
|||
field=models.CharField(choices=[('A', 'Sequencial por ano para cada autor'), ('B', 'Sequencial por ano indepententemente do autor'), ('L', 'Sequencial por legislatura'), ('U', 'Sequencial único')], default='A', max_length=1, verbose_name='Sequência de numeração'), |
|||
), |
|||
] |
|||
@ -0,0 +1,20 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Generated by Django 1.11.20 on 2019-04-15 13:50 |
|||
from __future__ import unicode_literals |
|||
|
|||
from django.db import migrations, models |
|||
|
|||
|
|||
class Migration(migrations.Migration): |
|||
|
|||
dependencies = [ |
|||
('materia', '0044_auto_20190327_1409'), |
|||
] |
|||
|
|||
operations = [ |
|||
migrations.AlterField( |
|||
model_name='tipomaterialegislativa', |
|||
name='sequencia_numeracao', |
|||
field=models.CharField(blank=True, choices=[('A', 'Sequencial por ano para cada autor'), ('B', 'Sequencial por ano indepententemente do autor'), ('L', 'Sequencial por legislatura'), ('U', 'Sequencial único')], max_length=1, verbose_name='Sequência de numeração'), |
|||
), |
|||
] |
|||
@ -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,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() |
|||
@ -0,0 +1,13 @@ |
|||
from sapl.materia.models import MateriaLegislativa |
|||
from sapl.protocoloadm.models import Protocolo |
|||
|
|||
|
|||
def main(): |
|||
for materia in MateriaLegislativa.objects.filter(numero_protocolo__isnull=False): |
|||
if not Protocolo.objects.filter(ano=materia.ano, numero=materia.numero_protocolo).exists(): |
|||
materia.numero_protocolo = None |
|||
materia.save() |
|||
|
|||
|
|||
if __name__ == '__main__': |
|||
main() |
|||
Loading…
Reference in new issue