Browse Source

Ajusta choices inválidas

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>
pull/431/head
Luciano Almeida 9 years ago
parent
commit
98d5030144
  1. 60
      legacy/migration.py
  2. 16
      materia/migrations/0031_merge.py
  3. 20
      norma/migrations/0013_auto_20160510_1404.py
  4. 12
      norma/models.py

60
legacy/migration.py

@ -13,8 +13,10 @@ from model_mommy.mommy import foreign_key_required, make
from base.models import ProblemaMigracao from base.models import ProblemaMigracao
from comissoes.models import Composicao, Participacao from comissoes.models import Composicao, Participacao
from materia.models import StatusTramitacao, Tramitacao
from parlamentares.models import Parlamentar from parlamentares.models import Parlamentar
from sessao.models import SessaoPlenaria from sessao.models import SessaoPlenaria, OrdemDia
from norma.models import NormaJuridica
# BASE ###################################################################### # BASE ######################################################################
@ -229,6 +231,7 @@ class DataMigrator:
def __init__(self): def __init__(self):
self.field_renames, self.model_renames = get_renames() self.field_renames, self.model_renames = get_renames()
self.data_mudada = {} self.data_mudada = {}
self.choice_valida = {}
def populate_renamed_fields(self, new, old): def populate_renamed_fields(self, new, old):
renames = self.field_renames[type(new)] renames = self.field_renames[type(new)]
@ -250,13 +253,8 @@ class DataMigrator:
value = get_fk_related(field, old_value, label) value = get_fk_related(field, old_value, label)
else: else:
value = getattr(old, old_field_name) value = getattr(old, old_field_name)
if (field_type == 'DateField' and if field_type == 'DateField' and \
field.null is False and value is None): not field.null 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' descricao = 'A data 0001-01-01 foi colocada no lugar'
warn(msg + warn(msg +
' => ' + descricao) ' => ' + descricao)
@ -264,17 +262,8 @@ class DataMigrator:
self.data_mudada['obj'] = new self.data_mudada['obj'] = new
self.data_mudada['descricao'] = descricao self.data_mudada['descricao'] = descricao
self.data_mudada['problema'] = msg self.data_mudada['problema'] = msg
else: if field_type in ('CharField', 'TextField') and field.blank \
value = '%d-01-01' % getattr(old, matches.group(0)) and value is None:
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 = '' value = ''
setattr(new, field.name, value) setattr(new, field.name, value)
@ -339,6 +328,9 @@ class DataMigrator:
# convert old records to new ones # convert old records to new ones
for old in old_records: for old in old_records:
if model.__name__ == 'SessaoPlenaria' and not old.pk:
old.delete()
continue
new = model() new = model()
self.populate_renamed_fields(new, old) self.populate_renamed_fields(new, old)
if adjust: if adjust:
@ -404,14 +396,44 @@ def adjust_parlamentar(new_parlamentar, old):
new_parlamentar.unidade_deliberativa = False 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): def adjust_sessaoplenaria(new, old):
assert not old.tip_expediente assert not old.tip_expediente
MIGRATION_ADJUSTMENTS = { MIGRATION_ADJUSTMENTS = {
NormaJuridica: adjust_normajuridica,
OrdemDia: adjust_ordemdia,
Participacao: adjust_participacao, Participacao: adjust_participacao,
Parlamentar: adjust_parlamentar, Parlamentar: adjust_parlamentar,
SessaoPlenaria: adjust_sessaoplenaria, SessaoPlenaria: adjust_sessaoplenaria,
StatusTramitacao: adjust_statustramitacao,
Tramitacao: adjust_tramitacao,
} }
# CHECKS #################################################################### # CHECKS ####################################################################

16
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 = [
]

20
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),
),
]

12
norma/models.py

@ -166,12 +166,18 @@ class LegislacaoCitada(models.Model):
class VinculoNormaJuridica(models.Model): class VinculoNormaJuridica(models.Model):
TIPO_VINCULO_CHOICES = ( TIPO_VINCULO_CHOICES = (
('A', _('Altera a norma')), ('A', _('Altera a norma')),
('R', _('Revoga a norma')), ('R', _('Revoga integralmente a norma')),
('P', _('Revoga parcialmente a norma')), ('P', _('Revoga parcialmente a norma')),
('T', _('Revoga por consolidação a norma')), ('T', _('Revoga integralmente por consolidação')),
('C', _('Norma correlata')), ('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')), ('G', _('Regulamenta a norma')),
('K', _('Suspende parcialmente a norma')),
('L', _('Suspende integralmente a norma')),
('N', _('Julgada integralmente inconstitucional')),
('O', _('Julgada parcialmente inconstitucional')),
) )
# TODO M2M ??? # TODO M2M ???

Loading…
Cancel
Save