Browse Source

Merge pull request #432 from interlegis/18-ajusta-assunto-em-norma

fix #18 Ajusta migração de assunto em norma jurídica
pull/492/head
Luciano Henrique Nunes de Almeida 9 years ago
parent
commit
df1ce2ca9e
  1. 47
      legacy/migration.py

47
legacy/migration.py

@ -14,7 +14,7 @@ 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 materia.models import StatusTramitacao, Tramitacao
from norma.models import NormaJuridica from norma.models import AssuntoNormaRelationship, NormaJuridica
from parlamentares.models import Parlamentar from parlamentares.models import Parlamentar
from protocoloadm.models import StatusTramitacaoAdministrativo from protocoloadm.models import StatusTramitacaoAdministrativo
from sessao.models import OrdemDia, SessaoPlenaria from sessao.models import OrdemDia, SessaoPlenaria
@ -261,16 +261,16 @@ class DataMigrator:
value = getattr(old, old_field_name) value = getattr(old, old_field_name)
if field_type == 'DateField' and \ if field_type == 'DateField' and \
not field.null and value is None: not field.null and value is None:
descricao = 'A data 0001-01-01 foi colocada no lugar' descricao = 'A data 0001-01-01 foi colocada no lugar'
problema = 'O valor da data era nulo ou inválido' problema = 'O valor da data era nulo ou inválido'
warn(msg + warn(msg +
' => ' + descricao) ' => ' + descricao)
value = '0001-01-01' value = '0001-01-01'
self.data_mudada['obj'] = new self.data_mudada['obj'] = new
self.data_mudada['descricao'] = descricao self.data_mudada['descricao'] = descricao
self.data_mudada['problema'] = problema self.data_mudada['problema'] = problema
self.data_mudada.setdefault('nome_campo', []).\ self.data_mudada.setdefault('nome_campo', []).\
append(field.name) append(field.name)
if field_type == 'CharField' or field_type == 'TextField': if field_type == 'CharField' or field_type == 'TextField':
if value is None: if value is None:
value = '' value = ''
@ -333,15 +333,18 @@ class DataMigrator:
old_records = legacy_model.objects.all().order_by(legacy_pk_name) old_records = legacy_model.objects.all().order_by(legacy_pk_name)
adjust = MIGRATION_ADJUSTMENTS.get(model) ajuste_antes_salvar = AJUSTE_ANTES_SALVAR.get(model)
ajuste_depois_salvar = AJUSTE_DEPOIS_SALVAR.get(model)
# convert old records to new ones # convert old records to new ones
for old in old_records: for old in old_records:
new = model() new = model()
self.populate_renamed_fields(new, old) self.populate_renamed_fields(new, old)
if adjust: if ajuste_antes_salvar:
adjust(new, old) ajuste_antes_salvar(new, old)
save(new, old) save(new, old)
if ajuste_depois_salvar:
ajuste_depois_salvar(new, old)
if self.data_mudada: if self.data_mudada:
save_relation(**self.data_mudada) save_relation(**self.data_mudada)
self.data_mudada.clear() self.data_mudada.clear()
@ -439,8 +442,16 @@ def adjust_sessaoplenaria(new, old):
assert not old.tip_expediente assert not old.tip_expediente
MIGRATION_ADJUSTMENTS = { def adjust_normajuridica(new, old):
NormaJuridica: adjust_normajuridica, lista_ids_assunto = old.cod_assunto.split(',')
for id_assunto in lista_ids_assunto:
relacao = AssuntoNormaRelationship()
relacao.assunto_id = int(id_assunto)
relacao.norma_id = new.pk
relacao.save()
AJUSTE_ANTES_SALVAR = {
OrdemDia: adjust_ordemdia, OrdemDia: adjust_ordemdia,
Participacao: adjust_participacao, Participacao: adjust_participacao,
Parlamentar: adjust_parlamentar, Parlamentar: adjust_parlamentar,
@ -450,6 +461,10 @@ MIGRATION_ADJUSTMENTS = {
Tramitacao: adjust_tramitacao, Tramitacao: adjust_tramitacao,
} }
AJUSTE_DEPOIS_SALVAR = {
NormaJuridica: adjust_normajuridica,
}
# CHECKS #################################################################### # CHECKS ####################################################################

Loading…
Cancel
Save