diff --git a/base/admin.py b/base/admin.py index 99f81f8af..b952b349c 100644 --- a/base/admin.py +++ b/base/admin.py @@ -11,7 +11,7 @@ admin.site.unregister(ProblemaMigracao) @admin.register(ProblemaMigracao) class ProblemaMigracaoAdmin(admin.ModelAdmin): - list_display = ["content_type", "object_id", "problema", + list_display = ["content_type", "object_id", "nome_campo", "problema", "descricao", "get_url"] def get_url(self, obj): diff --git a/base/migrations/0015_problemamigracao_nome_campo.py b/base/migrations/0015_problemamigracao_nome_campo.py new file mode 100644 index 000000000..07be71fb1 --- /dev/null +++ b/base/migrations/0015_problemamigracao_nome_campo.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.5 on 2016-05-10 20:34 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0014_auto_20160502_1635'), + ] + + operations = [ + migrations.AddField( + model_name='problemamigracao', + name='nome_campo', + field=models.CharField(blank=True, max_length=100, verbose_name='Nome do(s) Campo(s)'), + ), + ] diff --git a/base/models.py b/base/models.py index f1fb3811f..30a916c0c 100644 --- a/base/models.py +++ b/base/models.py @@ -54,6 +54,9 @@ class ProblemaMigracao(models.Model): verbose_name=_('Tipo de Content')) object_id = models.PositiveIntegerField(verbose_name=_('ID do Objeto')) content_object = GenericForeignKey('content_type', 'object_id') + nome_campo = models.CharField(max_length=100, + blank=True, + verbose_name='Nome do(s) Campo(s)') problema = models.CharField(max_length=300, verbose_name=_('Problema')) descricao = models.CharField(max_length=300, verbose_name=_('Descrição')) eh_stub = models.BooleanField(verbose_name='É stub?') diff --git a/legacy/migration.py b/legacy/migration.py index 781cfc101..5783fdfa2 100644 --- a/legacy/migration.py +++ b/legacy/migration.py @@ -113,7 +113,8 @@ def get_fk_related(field, value, label=None): value = mommy.make(field.related_model, **fields_dict) descricao = 'stub criado para campos não nuláveis!' - save_relation(value, msg, descricao, eh_stub=True) + save_relation(value, [field.name], msg, descricao, + eh_stub=True) warn(msg + ' => ' + descricao) else: value = None @@ -121,7 +122,8 @@ def get_fk_related(field, value, label=None): value = make_stub(field.related_model, value) descricao = 'stub criado para entrada orfã!' warn(msg + ' => ' + descricao) - save_relation(value, msg, descricao, eh_stub=True) + save_relation(value, [field.name], msg, descricao, + eh_stub=True) else: assert value return value @@ -204,9 +206,12 @@ def save_with_id(new, id): assert new.id == id, 'New id is different from provided!' -def save_relation(obj, problema='', descricao='', eh_stub=False): - link = ProblemaMigracao(content_object=obj, problema=problema, - descricao=descricao, eh_stub=eh_stub) +def save_relation(obj, nome_campo='', problema='', descricao='', + eh_stub=False): + link = ProblemaMigracao( + content_object=obj, nome_campo=nome_campo, problema=problema, + descricao=descricao, eh_stub=eh_stub, + ) link.save() @@ -256,16 +261,19 @@ class DataMigrator: value = getattr(old, old_field_name) if field_type == 'DateField' and \ not field.null and value is None: - descricao = 'A data 0001-01-01 foi colocada no lugar' - warn(msg + - ' => ' + descricao) - value = '0001-01-01' - self.data_mudada['obj'] = new - self.data_mudada['descricao'] = descricao - self.data_mudada['problema'] = msg - if field_type in ('CharField', 'TextField') and field.blank \ - and value is None: - value = '' + descricao = 'A data 0001-01-01 foi colocada no lugar' + problema = 'O valor da data era nulo ou inválido' + warn(msg + + ' => ' + descricao) + value = '0001-01-01' + self.data_mudada['obj'] = new + self.data_mudada['descricao'] = descricao + self.data_mudada['problema'] = problema + self.data_mudada.setdefault('nome_campo', []).\ + append(field.name) + if field_type == 'CharField' or field_type == 'TextField': + if value is None: + value = '' setattr(new, field.name, value) def migrate(self, obj=appconfs): @@ -466,7 +474,8 @@ def make_with_log(model, _quantity=None, make_m2m=False, **attrs): descricao = 'Essa entrada é necessária para um dos stubs criados' ' anteriormente' warn(problema) - save_relation(stub, problema, descricao, eh_stub=True) + save_relation(obj=stub, problema=problema, + descricao=descricao, eh_stub=True) return stub make_with_log.required = foreign_key_required