|
|
@ -104,7 +104,7 @@ def get_fk_related(field, value, label=None): |
|
|
|
field.name, value, |
|
|
|
field.model.__name__, label or '---') |
|
|
|
if value == 0: |
|
|
|
# se FK == 0, criamos um stub e colocamos o valor '???????? |
|
|
|
# se FK == 0, criamos um stub e colocamos o valor '????????' |
|
|
|
# para qualquer CharField ou TextField que possa haver |
|
|
|
if not field.null: |
|
|
|
all_fields = field.related_model._meta.get_fields() |
|
|
@ -177,7 +177,7 @@ class DataMigrator: |
|
|
|
for field in new._meta.fields: |
|
|
|
old_field_name = renames.get(field.name) |
|
|
|
field_type = field.get_internal_type() |
|
|
|
msg = ("Field %s (%s) from model %s " % |
|
|
|
msg = ("Campo %s (%s) da model %s " % |
|
|
|
(field.name, field_type, field.model.__name__)) |
|
|
|
if old_field_name: |
|
|
|
old_value = getattr(old, old_field_name) |
|
|
@ -187,7 +187,7 @@ class DataMigrator: |
|
|
|
old_type._meta.pk.name != 'id': |
|
|
|
label = old.pk |
|
|
|
else: |
|
|
|
label = '-- WITHOUT PK --' |
|
|
|
label = '-- SEM PK --' |
|
|
|
value = get_fk_related(field, old_value, label) |
|
|
|
else: |
|
|
|
value = getattr(old, old_field_name) |
|
|
@ -198,15 +198,17 @@ class DataMigrator: |
|
|
|
combined_names = "(" + ")|(".join(names) + ")" |
|
|
|
matches = re.search('(ano_\w+)', combined_names) |
|
|
|
if not matches: |
|
|
|
warn(msg + '=> setting 0000-01-01 value to DateField') |
|
|
|
warn(msg + |
|
|
|
'=> colocando valor 0000-01-01 para DateField') |
|
|
|
value = '0001-01-01' |
|
|
|
else: |
|
|
|
value = '%d-01-01' % getattr(old, matches.group(0)) |
|
|
|
warn(msg + "=> settig %s for not null DateField" % |
|
|
|
warn(msg + |
|
|
|
"=> colocando %s para DateField não nulável" % |
|
|
|
(value)) |
|
|
|
if field_type == 'CharField' or field_type == 'TextField': |
|
|
|
if value is None: |
|
|
|
warn(msg + "=> settig empty string '' for %s value" % |
|
|
|
warn(msg + "=> colocando string vazia para valor %s" % |
|
|
|
(value)) |
|
|
|
value = '' |
|
|
|
setattr(new, field.name, value) |
|
|
@ -215,13 +217,13 @@ class DataMigrator: |
|
|
|
# warning: model/app migration order is of utmost importance |
|
|
|
|
|
|
|
self.to_delete = [] |
|
|
|
info('Starting %s migration...' % obj) |
|
|
|
info('Começando migração: %s...' % obj) |
|
|
|
self._do_migrate(obj) |
|
|
|
# exclude logically deleted in legacy base |
|
|
|
info('Deleting models with ind_excluido...') |
|
|
|
info('Deletando models com ind_excluido...') |
|
|
|
for obj in self.to_delete: |
|
|
|
obj.delete() |
|
|
|
info('Deleting unnecessary stubs...') |
|
|
|
info('Deletando stubs desnecessários...') |
|
|
|
self.delete_stubs() |
|
|
|
|
|
|
|
def _do_migrate(self, obj): |
|
|
@ -239,7 +241,7 @@ class DataMigrator: |
|
|
|
'Parameter must be a Model, AppConfig or a sequence of them') |
|
|
|
|
|
|
|
def migrate_model(self, model): |
|
|
|
print('Migrating %s...' % model.__name__) |
|
|
|
print('Migrando %s...' % model.__name__) |
|
|
|
|
|
|
|
legacy_model_name = self.model_renames.get(model, model.__name__) |
|
|
|
legacy_model = legacy_app.get_model(legacy_model_name) |
|
|
@ -314,7 +316,7 @@ def adjust_parlamentar(new_parlamentar, old): |
|
|
|
# but data includes null values |
|
|
|
# => transform None to False |
|
|
|
if value is None: |
|
|
|
warn('null converted to False') |
|
|
|
warn('nulo convertido para falso') |
|
|
|
new_parlamentar.unidade_deliberativa = False |
|
|
|
|
|
|
|
|
|
|
|