From 98d503014412096c01f98c24efb2ab3857b4cd8f Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Tue, 10 May 2016 14:20:02 -0300 Subject: [PATCH 1/4] =?UTF-8?q?Ajusta=20choices=20inv=C3=A1lidas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- legacy/migration.py | 76 +++++++++++++-------- materia/migrations/0031_merge.py | 16 +++++ norma/migrations/0013_auto_20160510_1404.py | 20 ++++++ norma/models.py | 12 +++- 4 files changed, 94 insertions(+), 30 deletions(-) create mode 100644 materia/migrations/0031_merge.py create mode 100644 norma/migrations/0013_auto_20160510_1404.py diff --git a/legacy/migration.py b/legacy/migration.py index ddc8e0bfd..e4a21a368 100644 --- a/legacy/migration.py +++ b/legacy/migration.py @@ -13,8 +13,10 @@ from model_mommy.mommy import foreign_key_required, make from base.models import ProblemaMigracao from comissoes.models import Composicao, Participacao +from materia.models import StatusTramitacao, Tramitacao from parlamentares.models import Parlamentar -from sessao.models import SessaoPlenaria +from sessao.models import SessaoPlenaria, OrdemDia +from norma.models import NormaJuridica # BASE ###################################################################### @@ -229,6 +231,7 @@ class DataMigrator: def __init__(self): self.field_renames, self.model_renames = get_renames() self.data_mudada = {} + self.choice_valida = {} def populate_renamed_fields(self, new, old): renames = self.field_renames[type(new)] @@ -250,32 +253,18 @@ class DataMigrator: value = get_fk_related(field, old_value, label) else: value = getattr(old, old_field_name) - if (field_type == 'DateField' and - field.null is False and value is None): - names = [old_fields.name for old_fields - in old._meta.get_fields()] - combined_names = "(" + ")|(".join(names) + ")" - matches = re.search('(ano_\w+)', combined_names) - if not matches: - descricao = 'A data 0001-01-01 foi colocada no lugar' - warn(msg + - ' => ' + descricao) - value = '0001-01-01' - self.data_mudada['obj'] = new - self.data_mudada['descricao'] = descricao - self.data_mudada['problema'] = msg - else: - value = '%d-01-01' % getattr(old, matches.group(0)) - descricao = ('A data %s para foi colocada no lugar' - % value) - self.data_mudada['obj'] = new - self.data_mudada['descricao'] = descricao - self.data_mudada['problema'] = msg - warn(msg + - '=> ' + descricao) - if field_type == 'CharField' or field_type == 'TextField': - if value is None: - value = '' + if field_type == 'DateField' and \ + not field.null and value is None: + descricao = 'A data 0001-01-01 foi colocada no lugar' + warn(msg + + ' => ' + descricao) + value = '0001-01-01' + self.data_mudada['obj'] = new + self.data_mudada['descricao'] = descricao + self.data_mudada['problema'] = msg + if field_type in ('CharField', 'TextField') and field.blank \ + and value is None: + value = '' setattr(new, field.name, value) def migrate(self, obj=appconfs): @@ -339,6 +328,9 @@ class DataMigrator: # convert old records to new ones for old in old_records: + if model.__name__ == 'SessaoPlenaria' and not old.pk: + old.delete() + continue new = model() self.populate_renamed_fields(new, old) if adjust: @@ -404,14 +396,44 @@ def adjust_parlamentar(new_parlamentar, old): new_parlamentar.unidade_deliberativa = False +def adjust_normajuridica(new, old): + # O 'S' vem de 'Selecionar'. Na versão antiga do SAPL, quando uma opção do + # combobox era selecionada, o sistema pegava a primeira letra da seleção, + # sendo F para Federal, E para Estadual, M para Municipal e o S para + # Selecionar, que era a primeira opção quando nada era selecionado. + if old.tip_esfera_federacao == 'S': + new.esfera_federacao = '' + + +def adjust_ordemdia(new, old): + if not old.tip_votacao: + new.tipo_votacao = 1 + + +def adjust_statustramitacao(new, old): + if old.ind_fim_tramitacao: + new.indicador = 'R' + else: + new.indicador = 'F' + + +def adjust_tramitacao(new, old): + if old.sgl_turno == 'Ú': + new.turno = 'U' + + def adjust_sessaoplenaria(new, old): assert not old.tip_expediente MIGRATION_ADJUSTMENTS = { + NormaJuridica: adjust_normajuridica, + OrdemDia: adjust_ordemdia, Participacao: adjust_participacao, Parlamentar: adjust_parlamentar, SessaoPlenaria: adjust_sessaoplenaria, + StatusTramitacao: adjust_statustramitacao, + Tramitacao: adjust_tramitacao, } # CHECKS #################################################################### diff --git a/materia/migrations/0031_merge.py b/materia/migrations/0031_merge.py new file mode 100644 index 000000000..54efc9ec0 --- /dev/null +++ b/materia/migrations/0031_merge.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.5 on 2016-05-10 17:04 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0030_auto_20160502_1630'), + ('materia', '0030_auto_20160429_1349'), + ] + + operations = [ + ] diff --git a/norma/migrations/0013_auto_20160510_1404.py b/norma/migrations/0013_auto_20160510_1404.py new file mode 100644 index 000000000..97d780cb5 --- /dev/null +++ b/norma/migrations/0013_auto_20160510_1404.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.5 on 2016-05-10 17:04 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('norma', '0012_auto_20160309_1407'), + ] + + operations = [ + migrations.AlterField( + model_name='vinculonormajuridica', + name='tipo_vinculo', + field=models.CharField(blank=True, choices=[('A', 'Altera a norma'), ('R', 'Revoga integralmente a norma'), ('P', 'Revoga parcialmente a norma'), ('T', 'Revoga integralmente por consolidação'), ('C', 'Norma correlata'), ('S', 'Ressalva a norma'), ('E', 'Reedita a norma'), ('I', 'Reedita a norma com alteração'), ('G', 'Regulamenta a norma'), ('K', 'Suspende parcialmente a norma'), ('L', 'Suspende integralmente a norma'), ('N', 'Julgada integralmente inconstitucional'), ('O', 'Julgada parcialmente inconstitucional')], max_length=1), + ), + ] diff --git a/norma/models.py b/norma/models.py index 37d48d20b..5c05464b4 100644 --- a/norma/models.py +++ b/norma/models.py @@ -166,12 +166,18 @@ class LegislacaoCitada(models.Model): class VinculoNormaJuridica(models.Model): TIPO_VINCULO_CHOICES = ( ('A', _('Altera a norma')), - ('R', _('Revoga a norma')), + ('R', _('Revoga integralmente a norma')), ('P', _('Revoga parcialmente a norma')), - ('T', _('Revoga por consolidação a norma')), + ('T', _('Revoga integralmente por consolidação')), ('C', _('Norma correlata')), - ('I', _('Suspende a execução da norma')), + ('S', _('Ressalva a norma')), + ('E', _('Reedita a norma')), + ('I', _('Reedita a norma com alteração')), ('G', _('Regulamenta a norma')), + ('K', _('Suspende parcialmente a norma')), + ('L', _('Suspende integralmente a norma')), + ('N', _('Julgada integralmente inconstitucional')), + ('O', _('Julgada parcialmente inconstitucional')), ) # TODO M2M ??? From 9876434feaa0dfffd16fbc395f69e8742a86da5a Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Tue, 10 May 2016 15:21:33 -0300 Subject: [PATCH 2/4] Arruma ordem de imports Signed-off-by: Luciano Almeida --- legacy/migration.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/legacy/migration.py b/legacy/migration.py index e4a21a368..d4cb784b1 100644 --- a/legacy/migration.py +++ b/legacy/migration.py @@ -14,9 +14,9 @@ from model_mommy.mommy import foreign_key_required, make from base.models import ProblemaMigracao from comissoes.models import Composicao, Participacao from materia.models import StatusTramitacao, Tramitacao -from parlamentares.models import Parlamentar -from sessao.models import SessaoPlenaria, OrdemDia from norma.models import NormaJuridica +from parlamentares.models import Parlamentar +from sessao.models import OrdemDia, SessaoPlenaria # BASE ###################################################################### From 1f5dc1af446047403adc691949b50caf941fab7a Mon Sep 17 00:00:00 2001 From: Luciano Henrique Nunes de Almeida Date: Tue, 10 May 2016 15:45:08 -0300 Subject: [PATCH 3/4] Exclui arquivo conflituoso --- materia/migrations/0031_merge.py | 16 ---------------- 1 file changed, 16 deletions(-) delete mode 100644 materia/migrations/0031_merge.py diff --git a/materia/migrations/0031_merge.py b/materia/migrations/0031_merge.py deleted file mode 100644 index 54efc9ec0..000000000 --- a/materia/migrations/0031_merge.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.9.5 on 2016-05-10 17:04 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('materia', '0030_auto_20160502_1630'), - ('materia', '0030_auto_20160429_1349'), - ] - - operations = [ - ] From 49350cfb34b6c4750d6e9cee7d447b42efa73eff Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Thu, 19 May 2016 15:36:19 -0300 Subject: [PATCH 4/4] =?UTF-8?q?Ajusta=20migraca=C3=A7=C3=A3o=20de=20acordo?= =?UTF-8?q?=20com=20revis=C3=B5es=20propostas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- legacy/migration.py | 8 ++++---- materia/models.py | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/legacy/migration.py b/legacy/migration.py index d4cb784b1..4fcd75708 100644 --- a/legacy/migration.py +++ b/legacy/migration.py @@ -328,9 +328,6 @@ class DataMigrator: # convert old records to new ones for old in old_records: - if model.__name__ == 'SessaoPlenaria' and not old.pk: - old.delete() - continue new = model() self.populate_renamed_fields(new, old) if adjust: @@ -406,15 +403,18 @@ def adjust_normajuridica(new, old): def adjust_ordemdia(new, old): + # Prestar atenção if not old.tip_votacao: new.tipo_votacao = 1 def adjust_statustramitacao(new, old): if old.ind_fim_tramitacao: + new.indicador = 'F' + elif old.ind_retorno_tramitacao: new.indicador = 'R' else: - new.indicador = 'F' + new.indicador = '' def adjust_tramitacao(new, old): diff --git a/materia/models.py b/materia/models.py index 0eb2037c8..653c631f8 100644 --- a/materia/models.py +++ b/materia/models.py @@ -482,9 +482,8 @@ class StatusTramitacao(models.Model): sigla = models.CharField(max_length=10, verbose_name=_('Sigla')) descricao = models.CharField(max_length=60, verbose_name=_('Descrição')) - # TODO make specific migration considering both ind_fim_tramitacao, - # ind_retorno_tramitacao indicador = models.CharField( + blank=True, max_length=1, verbose_name=_('Indicador da Tramitação'), choices=INDICADOR_CHOICES)