Browse Source

Retira código desnecessário

pull/329/head
Marcio Mazza 9 years ago
parent
commit
ef49081329
  1. 25
      legacy/migration.py

25
legacy/migration.py

@ -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)
@ -186,7 +177,7 @@ def recreate_constraints():
for i in range(len(args)): for i in range(len(args)):
if isinstance(model._meta.get_field(args[i]), if isinstance(model._meta.get_field(args[i]),
models.ForeignKey): models.ForeignKey):
args[i] = args[i]+'_id' args[i] = args[i] + '_id'
args_string = '' args_string = ''
args_string += "(" + ', '.join(map(str, args)) + ")" args_string += "(" + ', '.join(map(str, args)) + ")"
exec_sql("ALTER TABLE %s ADD CONSTRAINT %s UNIQUE %s;" % exec_sql("ALTER TABLE %s ADD CONSTRAINT %s UNIQUE %s;" %
@ -205,7 +196,7 @@ def stub_desnecessario(obj):
if isinstance(obj, TipoMateriaLegislativa): if isinstance(obj, TipoMateriaLegislativa):
desnecessario = not any( desnecessario = not any(
rr.related_model.objects.filter( rr.related_model.objects.filter(
**{rr.field.name+'_origem_externa': obj}).exists() **{rr.field.name + '_origem_externa': obj}).exists()
for rr in lista) for rr in lista)
return desnecessario return desnecessario
@ -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'

Loading…
Cancel
Save