diff --git a/base/admin.py b/base/admin.py
index 0d8e82faf..37e400946 100644
--- a/base/admin.py
+++ b/base/admin.py
@@ -2,8 +2,7 @@ from django.contrib import admin
from base.models import ProblemaMigracao
from sapl.utils import register_all_models_in_admin
-from django.contrib import admin
-from base.models import ProblemaMigracao
+from django.core.urlresolvers import reverse
register_all_models_in_admin(__name__)
@@ -16,7 +15,9 @@ class ProblemaMigracaoAdmin(admin.ModelAdmin):
"descricao", "get_url"]
def get_url(self, obj):
- return "%s" % (obj.endereco, obj.endereco)
+ info = (obj._meta.app_label, obj._meta.model_name)
+ endereco = reverse('admin:%s_%s_change' % info, args=(obj.pk,))
+ return "%s" % (endereco, endereco)
- get_url.short_description = "Endereco"
+ get_url.short_description = "Endereço"
get_url.allow_tags = True
diff --git a/base/migrations/0013_remove_problemamigracao_endereco.py b/base/migrations/0013_remove_problemamigracao_endereco.py
new file mode 100644
index 000000000..67526693d
--- /dev/null
+++ b/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',
+ ),
+ ]
diff --git a/base/models.py b/base/models.py
index 8af741c0d..9a94c9eb8 100644
--- a/base/models.py
+++ b/base/models.py
@@ -2,8 +2,6 @@ from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
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
@@ -59,7 +57,6 @@ class ProblemaMigracao(models.Model):
verbose_name=_('Problema'))
descricao = models.CharField(max_length=300, null=True,
verbose_name=_('Descrição'))
- endereco = models.URLField(null=True, verbose_name=_('Endereço'))
eh_stub = models.BooleanField(verbose_name='É stub?')
class Meta:
diff --git a/legacy/migration.py b/legacy/migration.py
index f1210d363..d69da781c 100644
--- a/legacy/migration.py
+++ b/legacy/migration.py
@@ -130,11 +130,6 @@ def get_field(model, 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'):
cursor = connections[db].cursor()
cursor.execute(sql)
@@ -185,18 +180,13 @@ def recreate_constraints():
def stub_desnecessario(obj):
- lista = [
+ lista_fields = [
f for f in obj._meta.get_fields()
if (f.one_to_many or f.one_to_one) and f.auto_created
]
desnecessario = not any(
rr.related_model.objects.filter(**{rr.field.name: obj}).exists()
- for rr in lista if rr)
- 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)
+ for rr in lista_fields)
return desnecessario
@@ -215,8 +205,7 @@ def save_with_id(new, id):
def save_relation(obj, problema='', descricao='', eh_stub=False):
link = ProblemaMigracao(content_object=obj, problema=problema,
- descricao=descricao, endereco=get_url(obj),
- eh_stub=eh_stub)
+ descricao=descricao, eh_stub=eh_stub)
link.save()
@@ -272,7 +261,7 @@ class DataMigrator:
if not matches:
descricao = 'A data 0001-01-01 foi colocada no lugar'
warn(msg +
- '=> ' + descricao)
+ ' => ' + descricao)
value = '0001-01-01'
self.data_mudada['obj'] = new
self.data_mudada['descricao'] = descricao
diff --git a/materia/models.py b/materia/models.py
index c241f7632..08d5165f6 100644
--- a/materia/models.py
+++ b/materia/models.py
@@ -80,7 +80,7 @@ class MateriaLegislativa(models.Model):
TipoMateriaLegislativa,
blank=True,
null=True,
- related_name='+',
+ related_name='tipo_origem_externa_set',
verbose_name=_('Tipo'))
numero_origem_externa = models.CharField(
max_length=5, blank=True, verbose_name=_('Número'))