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. 27
      legacy/migration.py

27
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
@ -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