Browse Source

Valida assuntos repetidos

pull/772/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
9d926bd7eb
  1. 29
      sapl/norma/forms.py
  2. 23
      sapl/norma/migrations/0016_auto_20161027_1419.py
  3. 2
      sapl/norma/models.py
  4. 8
      sapl/norma/views.py

29
sapl/norma/forms.py

@ -8,12 +8,11 @@ from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.materia.models import (AssuntoNormaRelationship, MateriaLegislativa,
TipoMateriaLegislativa)
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa
from sapl.settings import MAX_DOC_UPLOAD_SIZE
from sapl.utils import RANGE_ANOS
from .models import NormaJuridica
from .models import AssuntoNormaRelationship, NormaJuridica
def get_esferas():
@ -37,18 +36,18 @@ class AssuntoNormaRelationshipForm(ModelForm):
model = AssuntoNormaRelationship
fields = ['assunto']
def clean(self):
cleaned_data = self.cleaned_data
import ipdb; ipdb.set_trace()
# try:
# comissao = Comissao.objects.get(id=self.initial['comissao'])
# except ObjectDoesNotExist:
# msg = _('A localização atual deve ser uma comissão.')
# raise ValidationError(msg)
# else:
# cleaned_data['comissao'] = comissao
return cleaned_data
def save(self, commit=False):
norma_assunto = super(AssuntoNormaRelationshipForm, self).save(commit)
try:
AssuntoNormaRelationship.objects.get(
norma=norma_assunto.norma,
assunto=norma_assunto.assunto)
except ObjectDoesNotExist:
norma_assunto.save()
else:
raise forms.ValidationError(
"Esse Assunto já está anexado nesta Norma Jurídica.")
return norma_assunto
# TODO termos, pesquisa textual, assunto(M2M)

23
sapl/norma/migrations/0016_auto_20161027_1419.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-10-27 14:19
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('norma', '0015_auto_20160929_1635'),
]
operations = [
migrations.AlterModelOptions(
name='assuntonormarelationship',
options={'verbose_name': 'Assunto', 'verbose_name_plural': 'Assuntos'},
),
migrations.AlterUniqueTogether(
name='assuntonormarelationship',
unique_together=set([]),
),
]

2
sapl/norma/models.py

@ -148,7 +148,7 @@ class AssuntoNormaRelationship(models.Model):
verbose_name_plural = _('Assuntos')
def __str__(self):
return self.assunto
return self.assunto.assunto
class LegislacaoCitada(models.Model):

8
sapl/norma/views.py

@ -11,7 +11,7 @@ from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux,
MasterDetailCrud, make_pagination)
from sapl.norma.forms import NormaJuridicaForm
from .forms import NormaJuridicaPesquisaForm
from .forms import AssuntoNormaRelationshipForm, NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, AssuntoNormaRelationship, NormaJuridica,
TipoNormaJuridica)
@ -51,6 +51,12 @@ class AssuntoNormaRelationshipCrud(MasterDetailCrud):
list_field_names = ['assunto']
ordering = 'assunto'
class CreateView(MasterDetailCrud.CreateView):
form_class = AssuntoNormaRelationshipForm
class UpdateView(MasterDetailCrud.UpdateView):
form_class = AssuntoNormaRelationshipForm
class NormaCrud(Crud):
model = NormaJuridica

Loading…
Cancel
Save