Browse Source

Ajusta sugestões de correção do PR

Signed-off-by: Luciano Almeida <lucianoalmeida@interlegis.leg.br>
pull/329/head
Luciano Almeida 9 years ago
parent
commit
9af25222de
  1. 9
      base/admin.py
  2. 19
      base/migrations/0013_remove_problemamigracao_endereco.py
  3. 3
      base/models.py
  4. 19
      legacy/migration.py
  5. 2
      materia/models.py

9
base/admin.py

@ -2,8 +2,7 @@ from django.contrib import admin
from base.models import ProblemaMigracao from base.models import ProblemaMigracao
from sapl.utils import register_all_models_in_admin from sapl.utils import register_all_models_in_admin
from django.contrib import admin from django.core.urlresolvers import reverse
from base.models import ProblemaMigracao
register_all_models_in_admin(__name__) register_all_models_in_admin(__name__)
@ -16,7 +15,9 @@ class ProblemaMigracaoAdmin(admin.ModelAdmin):
"descricao", "get_url"] "descricao", "get_url"]
def get_url(self, obj): def get_url(self, obj):
return "<a href='%s'>%s</a>" % (obj.endereco, obj.endereco) info = (obj._meta.app_label, obj._meta.model_name)
endereco = reverse('admin:%s_%s_change' % info, args=(obj.pk,))
return "<a href='%s'>%s</a>" % (endereco, endereco)
get_url.short_description = "Endereco" get_url.short_description = "Endereço"
get_url.allow_tags = True get_url.allow_tags = True

19
base/migrations/0013_remove_problemamigracao_endereco.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.5 on 2016-05-02 17:36
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('base', '0012_problemamigracao_eh_stub'),
]
operations = [
migrations.RemoveField(
model_name='problemamigracao',
name='endereco',
),
]

3
base/models.py

@ -2,8 +2,6 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db import models from django.db import models
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from sapl.utils import UF from sapl.utils import UF
@ -59,7 +57,6 @@ class ProblemaMigracao(models.Model):
verbose_name=_('Problema')) verbose_name=_('Problema'))
descricao = models.CharField(max_length=300, null=True, descricao = models.CharField(max_length=300, null=True,
verbose_name=_('Descrição')) verbose_name=_('Descrição'))
endereco = models.URLField(null=True, verbose_name=_('Endereço'))
eh_stub = models.BooleanField(verbose_name='É stub?') eh_stub = models.BooleanField(verbose_name='É stub?')
class Meta: class Meta:

19
legacy/migration.py

@ -130,11 +130,6 @@ def get_field(model, fieldname):
return model._meta.get_field(fieldname) return model._meta.get_field(fieldname)
def get_url(object):
info = (object._meta.app_label, object._meta.model_name)
return reverse('admin:%s_%s_change' % info, args=(object.pk,))
def exec_sql(sql, db='default'): def exec_sql(sql, db='default'):
cursor = connections[db].cursor() cursor = connections[db].cursor()
cursor.execute(sql) cursor.execute(sql)
@ -185,18 +180,13 @@ def recreate_constraints():
def stub_desnecessario(obj): def stub_desnecessario(obj):
lista = [ lista_fields = [
f for f in obj._meta.get_fields() f for f in obj._meta.get_fields()
if (f.one_to_many or f.one_to_one) and f.auto_created if (f.one_to_many or f.one_to_one) and f.auto_created
] ]
desnecessario = not any( desnecessario = not any(
rr.related_model.objects.filter(**{rr.field.name: obj}).exists() rr.related_model.objects.filter(**{rr.field.name: obj}).exists()
for rr in lista if rr) for rr in lista_fields)
if isinstance(obj, TipoMateriaLegislativa):
desnecessario = not any(
rr.related_model.objects.filter(
**{rr.field.name + '_origem_externa': obj}).exists()
for rr in lista if rr)
return desnecessario return desnecessario
@ -215,8 +205,7 @@ def save_with_id(new, id):
def save_relation(obj, problema='', descricao='', eh_stub=False): def save_relation(obj, problema='', descricao='', eh_stub=False):
link = ProblemaMigracao(content_object=obj, problema=problema, link = ProblemaMigracao(content_object=obj, problema=problema,
descricao=descricao, endereco=get_url(obj), descricao=descricao, eh_stub=eh_stub)
eh_stub=eh_stub)
link.save() link.save()
@ -272,7 +261,7 @@ class DataMigrator:
if not matches: if not matches:
descricao = 'A data 0001-01-01 foi colocada no lugar' descricao = 'A data 0001-01-01 foi colocada no lugar'
warn(msg + warn(msg +
'=> ' + descricao) ' => ' + descricao)
value = '0001-01-01' value = '0001-01-01'
self.data_mudada['obj'] = new self.data_mudada['obj'] = new
self.data_mudada['descricao'] = descricao self.data_mudada['descricao'] = descricao

2
materia/models.py

@ -80,7 +80,7 @@ class MateriaLegislativa(models.Model):
TipoMateriaLegislativa, TipoMateriaLegislativa,
blank=True, blank=True,
null=True, null=True,
related_name='+', related_name='tipo_origem_externa_set',
verbose_name=_('Tipo')) verbose_name=_('Tipo'))
numero_origem_externa = models.CharField( numero_origem_externa = models.CharField(
max_length=5, blank=True, verbose_name=_('Número')) max_length=5, blank=True, verbose_name=_('Número'))

Loading…
Cancel
Save