Browse Source

Fix #1196

pull/1206/head
LeandroRoberto 8 years ago
parent
commit
32dd4fa03e
  1. 13
      sapl/materia/forms.py
  2. 20
      sapl/materia/migrations/0007_auto_20170620_1252.py
  3. 8
      sapl/materia/models.py

13
sapl/materia/forms.py

@ -8,8 +8,7 @@ from crispy_forms.layout import (HTML, Button, Column, Div, Field, Fieldset,
Layout, Submit) Layout, Submit)
from django import forms from django import forms
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist, ValidationError,\ from django.core.exceptions import ObjectDoesNotExist, ValidationError
NON_FIELD_ERRORS
from django.core.files.base import File from django.core.files.base import File
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db import models, transaction from django.db import models, transaction
@ -820,8 +819,12 @@ class TipoProposicaoForm(ModelForm):
) % (cd['tipo_conteudo_related'], content_type)) ) % (cd['tipo_conteudo_related'], content_type))
unique_value = self._meta.model.objects.filter( unique_value = self._meta.model.objects.filter(
content_type=content_type, object_id=cd['tipo_conteudo_related'] content_type=content_type, object_id=cd['tipo_conteudo_related'])
).first()
if self.instance.pk:
unique_value = unique_value.exclude(pk=self.instance.pk)
unique_value = unique_value.first()
if unique_value: if unique_value:
raise ValidationError( raise ValidationError(
@ -831,7 +834,7 @@ class TipoProposicaoForm(ModelForm):
content_type, content_type,
unique_value.tipo_conteudo_related)) unique_value.tipo_conteudo_related))
return self.cleaned_data return super().clean()
@transaction.atomic @transaction.atomic
def save(self, commit=False): def save(self, commit=False):

20
sapl/materia/migrations/0007_auto_20170620_1252.py

@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.13 on 2017-06-20 12:52
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('materia', '0006_merge'),
]
operations = [
migrations.AlterField(
model_name='tipoproposicao',
name='descricao',
field=models.CharField(error_messages={'unique': 'Já existe um Tipo de Proposição com esta descrição.'}, max_length=50, unique=True, verbose_name='Descrição'),
),
]

8
sapl/materia/models.py

@ -34,7 +34,13 @@ def grupo_autor():
@reversion.register() @reversion.register()
class TipoProposicao(models.Model): class TipoProposicao(models.Model):
descricao = models.CharField(max_length=50, verbose_name=_('Descrição')) descricao = models.CharField(
max_length=50,
verbose_name=_('Descrição'),
unique=True,
error_messages={
'unique': _('Já existe um Tipo de Proposição com esta descrição.')
})
# FIXME - para a rotina de migração - estes campos mudaram # FIXME - para a rotina de migração - estes campos mudaram
# retire o comentário quando resolver # retire o comentário quando resolver

Loading…
Cancel
Save