diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 054854e54..62c86451b 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -669,10 +669,16 @@ class AutorForm(ModelForm): autor = super(AutorForm, self).save(commit) - u = User.objects.get_or_create( - username=autor.username, - email=autor.email) - u = u[0] + try: + u = User.objects.get( + username=autor.username, + email=autor.email) + except ObjectDoesNotExist: + msg = _('Este nome de usuario não está cadastrado. ' + + 'Por favor, cadastre-o no Administrador do ' + + 'Sistema antes de adicioná-lo como Autor') + raise ValidationError(msg) + u.set_password(self.cleaned_data['senha']) u.is_active = False u.save() diff --git a/sapl/materia/migrations/0046_auto_20160825_1833.py b/sapl/materia/migrations/0046_auto_20160825_1833.py new file mode 100644 index 000000000..25b586eb3 --- /dev/null +++ b/sapl/materia/migrations/0046_auto_20160825_1833.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-08-25 21:33 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0045_auto_20160823_1658'), + ] + + operations = [ + migrations.AlterField( + model_name='autor', + name='user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index c38d76c0a..26380163c 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -208,7 +208,9 @@ class TipoAutor(models.Model): class Autor(models.Model): - user = models.ForeignKey(User) + user = models.ForeignKey(User, + blank=True, + null=True) partido = models.ForeignKey(Partido, blank=True, null=True) comissao = models.ForeignKey(Comissao, blank=True, null=True) parlamentar = models.ForeignKey(Parlamentar, blank=True, null=True)