Browse Source

Protege referência de Autor para seu tipo

Fix #2143
pull/2147/head
Marcio Mazza 6 years ago
parent
commit
131c8029d7
  1. 21
      sapl/base/migrations/0019_auto_20180815_1025.py
  2. 26
      sapl/base/models.py
  3. 4
      sapl/crud/base.py

21
sapl/base/migrations/0019_auto_20180815_1025.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2018-08-15 13:25
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('base', '0018_auto_20180801_1652'),
]
operations = [
migrations.AlterField(
model_name='autor',
name='tipo',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='base.TipoAutor', verbose_name='Tipo do Autor'),
),
]

26
sapl/base/models.py

@ -5,6 +5,7 @@ from django.db import models
from django.db.models.signals import post_migrate
from django.db.utils import DEFAULT_DB_ALIAS
from django.utils.translation import ugettext_lazy as _
from sapl.utils import (LISTA_DE_UFS, YES_NO_CHOICES,
get_settings_auth_user_model, models_with_gr_for_model)
@ -178,7 +179,8 @@ class Autor(models.Model):
on_delete=models.SET_NULL,
null=True)
tipo = models.ForeignKey(TipoAutor, verbose_name=_('Tipo do Autor'))
tipo = models.ForeignKey(TipoAutor, verbose_name=_('Tipo do Autor'),
on_delete=models.PROTECT)
content_type = models.ForeignKey(
ContentType,
@ -199,23 +201,17 @@ class Autor(models.Model):
ordering = ('nome',)
def __str__(self):
if self.autor_related:
return str(self.autor_related)
else:
if str(self.cargo):
return _('%(nome)s - %(cargo)s') % {
'nome': self.nome, 'cargo': self.cargo}
else:
return str(self.nome)
"""if str(self.tipo) == 'Parlamentar' and self.parlamentar:
return self.parlamentar.nome_parlamentar
elif str(self.tipo) == 'Comissao' and self.comissao:
return str(self.comissao)
elif str(self.tipo) == 'Partido' and self.partido:
return str(self.partido)
else:
"""
if self.nome:
if self.cargo:
return '{} - {}'.format(self.nome, self.cargo)
else:
return str(self.nome)
if self.user:
return str(self.user.username)
return '?'
def cria_models_tipo_autor(app_config=None, verbosity=2, interactive=True,

4
sapl/crud/base.py

@ -851,7 +851,9 @@ class CrudDeleteView(PermissionRequiredContainerCrudMixin,
é referenciado por outros registros:<br>\
<ul>'
for i in err.protected_objects:
error_msg += '<li>' + i.__str__() + '</li>'
error_msg += '<li>{} - {}</li>'.format(
i._meta.verbose_name, i
)
error_msg += '</ul>'
messages.add_message(request,

Loading…
Cancel
Save