From 967a465d08d114d618c0961b08054fddbbf22c3f Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Mon, 7 Mar 2016 15:52:49 -0300 Subject: [PATCH] Muda valores nulos de CharFields e TextFields Signed-off-by: Luciano Almeida --- legacy/migration.py | 9 ++++++++ .../0012_parlamentar_unidade_deliberativa.py | 21 +++++++++++++++++++ parlamentares/models.py | 3 +++ sessao/legacy.yaml | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 parlamentares/migrations/0012_parlamentar_unidade_deliberativa.py diff --git a/legacy/migration.py b/legacy/migration.py index 1da5ddf67..a04b69e57 100644 --- a/legacy/migration.py +++ b/legacy/migration.py @@ -159,6 +159,10 @@ 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' % ( + field.name, field_type, field.model.__name__) + if old_field_name: old_value = getattr(old, old_field_name) if isinstance(field, models.ForeignKey): @@ -171,6 +175,11 @@ class DataMigrator: value = get_fk_related(field, old_value, label) else: value = getattr(old, old_field_name) + if field_type == 'CharField' or field_type == 'TextField': + if value is None: + warn(msg + + " => settig empty string '' for %s value" % value) + value = '' setattr(new, field.name, value) def migrate(self, obj=appconfs): diff --git a/parlamentares/migrations/0012_parlamentar_unidade_deliberativa.py b/parlamentares/migrations/0012_parlamentar_unidade_deliberativa.py new file mode 100644 index 000000000..6c6e63bcd --- /dev/null +++ b/parlamentares/migrations/0012_parlamentar_unidade_deliberativa.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9 on 2016-03-07 17:58 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('parlamentares', '0011_auto_20160216_1015'), + ] + + operations = [ + migrations.AddField( + model_name='parlamentar', + name='unidade_deliberativa', + field=models.BooleanField(default=True, verbose_name='Unidade Deliberativa'), + preserve_default=False, + ), + ] diff --git a/parlamentares/models.py b/parlamentares/models.py index a1055602d..23f74aa17 100644 --- a/parlamentares/models.py +++ b/parlamentares/models.py @@ -237,6 +237,9 @@ class Parlamentar(models.Model): ativo = models.BooleanField(verbose_name=_('Ativo na Casa?')) biografia = models.TextField( blank=True, verbose_name=_('Biografia')) + # XXX Esse atribuito foi colocado aqui para não atrapalhar a migração + unidade_deliberativa = models.BooleanField( + verbose_name=_('Unidade Deliberativa')) fotografia = models.ImageField( blank=True, null=True, diff --git a/sessao/legacy.yaml b/sessao/legacy.yaml index a1321b96b..6e2cc2428 100644 --- a/sessao/legacy.yaml +++ b/sessao/legacy.yaml @@ -76,4 +76,4 @@ VotoParlamentar (RegistroVotacaoParlamentar): SessaoPlenariaPresenca: data_sessao: dat_sessao parlamentar: cod_parlamentar - sessao_plen: cod_sessao_plen + sessao_plenaria: cod_sessao_plen