Browse Source

Corrige mapeamento dos campos legados de models abstratos

pull/2023/head
Marcio Mazza 7 years ago
parent
commit
e9f38dd062
  1. 22
      sapl/legacy/migracao_dados.py
  2. 12
      sapl/sessao/legacy.yaml

22
sapl/legacy/migracao_dados.py

@ -87,15 +87,24 @@ for a1, s1 in name_sets:
# RENAMES ###################################################################
MODEL_RENAME_PATTERN = re.compile('(.+) \((.+)\)')
MODEL_RENAME_INCLUDE_PATTERN = re.compile('<(.+)>')
def get_renames():
field_renames = {}
model_renames = {}
includes = {}
for app in appconfs:
app_rename_data = yaml.load(
pkg_resources.resource_string(app.module.__name__, 'legacy.yaml'))
for model_name, renames in app_rename_data.items():
# armazena ou substitui includes
if MODEL_RENAME_INCLUDE_PATTERN.match(model_name):
includes[model_name] = renames
continue
elif isinstance(renames, str):
renames = includes[renames]
# detecta mudança de nome
match = MODEL_RENAME_PATTERN.match(model_name)
if match:
model_name, old_name = match.groups()
@ -106,19 +115,6 @@ def get_renames():
model_renames[model] = old_name
field_renames[model] = renames
# collect renames from parent classes
for model, renames in field_renames.items():
if any(parent in field_renames for parent in model.__mro__[1:]):
renames = {}
for parent in reversed(model.__mro__):
if parent in field_renames:
renames.update(field_renames[parent])
field_renames[model] = renames
# remove abstract classes
field_renames = {m: r for m, r in field_renames.items()
if not m._meta.abstract}
return field_renames, model_renames

12
sapl/sessao/legacy.yaml

@ -15,7 +15,7 @@ SessaoPlenaria:
url_audio: url_audio
url_video: url_video
AbstractOrdemDia:
<AbstractOrdemDia>:
data_ordem: dat_ordem
materia: cod_materia
numero_ordem: num_ordem
@ -24,7 +24,7 @@ AbstractOrdemDia:
sessao_plenaria: cod_sessao_plen
tipo_votacao: tip_votacao
ExpedienteMateria: {}
ExpedienteMateria: <AbstractOrdemDia>
TipoExpediente:
nome: nom_expediente
@ -39,17 +39,17 @@ IntegranteMesa (MesaSessaoPlenaria):
parlamentar: cod_parlamentar
sessao_plenaria: cod_sessao_plen
AbstractOrador:
<AbstractOrador>:
numero_ordem: num_ordem
parlamentar: cod_parlamentar
sessao_plenaria: cod_sessao_plen
url_discurso: url_discurso
Orador (Oradores): {}
Orador (Oradores): <AbstractOrador>
OradorExpediente (OradoresExpediente): {}
OradorExpediente (OradoresExpediente): <AbstractOrador>
OrdemDia: {}
OrdemDia: <AbstractOrdemDia>
PresencaOrdemDia (OrdemDiaPresenca):
parlamentar: cod_parlamentar

Loading…
Cancel
Save