|
@ -7,11 +7,10 @@ from django.apps.config import AppConfig |
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
from django.core.exceptions import ObjectDoesNotExist |
|
|
from django.core.urlresolvers import reverse |
|
|
from django.core.urlresolvers import reverse |
|
|
from django.db import connections, models |
|
|
from django.db import connections, models |
|
|
from django.db.models import CharField, ForeignKey, TextField |
|
|
from django.db.models import CharField, TextField |
|
|
from django.db.models.base import ModelBase |
|
|
from django.db.models.base import ModelBase |
|
|
|
|
|
|
|
|
from model_mommy import mommy |
|
|
from model_mommy import mommy |
|
|
from model_mommy.mommy import make, foreign_key_required |
|
|
from model_mommy.mommy import foreign_key_required, make |
|
|
|
|
|
|
|
|
from base.models import ProblemaMigracao |
|
|
from base.models import ProblemaMigracao |
|
|
from comissoes.models import Composicao, Participacao |
|
|
from comissoes.models import Composicao, Participacao |
|
@ -97,7 +96,6 @@ def warn(msg): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_fk_related(field, value, label=None): |
|
|
def get_fk_related(field, value, label=None): |
|
|
# fields_dict = {} |
|
|
|
|
|
if value is None and field.null is False: |
|
|
if value is None and field.null is False: |
|
|
value = 0 |
|
|
value = 0 |
|
|
if value is not None: |
|
|
if value is not None: |
|
@ -109,14 +107,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 '????????' |
|
|
|
|
|
# para qualquer CharField ou TextField que possa haver |
|
|
|
|
|
if not field.null: |
|
|
if not field.null: |
|
|
# all_fields = field.related_model._meta.get_fields() |
|
|
|
|
|
# fields_dict = {f.name: '????????????'[:f.max_length] |
|
|
|
|
|
# for f in all_fields |
|
|
|
|
|
# if isinstance(f, (CharField, TextField)) and |
|
|
|
|
|
# not f.choices and not f.blank} |
|
|
|
|
|
fields_dict = get_fields_dict(field.related_model) |
|
|
fields_dict = get_fields_dict(field.related_model) |
|
|
value = mommy.make(field.related_model, |
|
|
value = mommy.make(field.related_model, |
|
|
**fields_dict) |
|
|
**fields_dict) |
|
@ -248,6 +239,7 @@ def get_fields_dict(model): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class DataMigrator: |
|
|
class DataMigrator: |
|
|
|
|
|
|
|
|
def __init__(self): |
|
|
def __init__(self): |
|
|
self.field_renames, self.model_renames = get_renames() |
|
|
self.field_renames, self.model_renames = get_renames() |
|
|
|
|
|
|
|
@ -286,10 +278,7 @@ class DataMigrator: |
|
|
warn(msg + |
|
|
warn(msg + |
|
|
"=> colocando %s para DateField não nulável" % |
|
|
"=> colocando %s para DateField não nulável" % |
|
|
(value)) |
|
|
(value)) |
|
|
if field_type == 'CharField' or field_type == 'TextField': |
|
|
if field_type in ['CharField', 'TextField'] and value is None: |
|
|
if value is None: |
|
|
|
|
|
warn(msg + "=> colocando string vazia para valor %s" % |
|
|
|
|
|
(value)) |
|
|
|
|
|
value = '' |
|
|
value = '' |
|
|
setattr(new, field.name, value) |
|
|
setattr(new, field.name, value) |
|
|
|
|
|
|
|
@ -445,8 +434,6 @@ def check_app_no_ind_excluido(app): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def make_with_log(model, _quantity=None, make_m2m=False, **attrs): |
|
|
def make_with_log(model, _quantity=None, make_m2m=False, **attrs): |
|
|
import ipdb; ipdb.set_trace() |
|
|
|
|
|
all_fields = model._meta.get_fields() |
|
|
|
|
|
fields_dict = get_fields_dict(model) |
|
|
fields_dict = get_fields_dict(model) |
|
|
stub = make(model, _quantity, make_m2m, **fields_dict) |
|
|
stub = make(model, _quantity, make_m2m, **fields_dict) |
|
|
problema = 'Um stub foi necessário durante a criação de um outro stub' |
|
|
problema = 'Um stub foi necessário durante a criação de um outro stub' |
|
|