Browse Source

Merge pull request #438 from interlegis/434-adiciona-field-problematico

fix #434 Adiciona field de campos problemáticos
pull/432/head
Luciano Henrique Nunes de Almeida 9 years ago
parent
commit
e446377279
  1. 2
      base/admin.py
  2. 20
      base/migrations/0015_problemamigracao_nome_campo.py
  3. 3
      base/models.py
  4. 41
      legacy/migration.py

2
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):

20
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)'),
),
]

3
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?')

41
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

Loading…
Cancel
Save