Browse Source

Arruma conflito com master e traduz textos de info

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>
pull/329/head
Luciano Almeida 9 years ago
parent
commit
7c94e0591d
  1. 24
      legacy/migration.py

24
legacy/migration.py

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

Loading…
Cancel
Save