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 django.utils.translation import ugettext_lazy as _
from sapl.crispy_layout_mixin import form_actions, to_row from sapl.crispy_layout_mixin import form_actions, to_row
from sapl.materia.models import (AssuntoNormaRelationship, MateriaLegislativa, from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa
TipoMateriaLegislativa)
from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.settings import MAX_DOC_UPLOAD_SIZE
from sapl.utils import RANGE_ANOS from sapl.utils import RANGE_ANOS
from .models import NormaJuridica from .models import AssuntoNormaRelationship, NormaJuridica
def get_esferas(): def get_esferas():
@ -37,18 +36,18 @@ class AssuntoNormaRelationshipForm(ModelForm):
model = AssuntoNormaRelationship model = AssuntoNormaRelationship
fields = ['assunto'] fields = ['assunto']
def clean(self): def save(self, commit=False):
cleaned_data = self.cleaned_data norma_assunto = super(AssuntoNormaRelationshipForm, self).save(commit)
import ipdb; ipdb.set_trace() try:
# try: AssuntoNormaRelationship.objects.get(
# comissao = Comissao.objects.get(id=self.initial['comissao']) norma=norma_assunto.norma,
# except ObjectDoesNotExist: assunto=norma_assunto.assunto)
# msg = _('A localização atual deve ser uma comissão.') except ObjectDoesNotExist:
# raise ValidationError(msg) norma_assunto.save()
# else: else:
# cleaned_data['comissao'] = comissao raise forms.ValidationError(
"Esse Assunto já está anexado nesta Norma Jurídica.")
return cleaned_data return norma_assunto
# TODO termos, pesquisa textual, assunto(M2M) # 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') verbose_name_plural = _('Assuntos')
def __str__(self): def __str__(self):
return self.assunto return self.assunto.assunto
class LegislacaoCitada(models.Model): 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) MasterDetailCrud, make_pagination)
from sapl.norma.forms import NormaJuridicaForm from sapl.norma.forms import NormaJuridicaForm
from .forms import NormaJuridicaPesquisaForm from .forms import AssuntoNormaRelationshipForm, NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, AssuntoNormaRelationship, NormaJuridica, from .models import (AssuntoNorma, AssuntoNormaRelationship, NormaJuridica,
TipoNormaJuridica) TipoNormaJuridica)
@ -51,6 +51,12 @@ class AssuntoNormaRelationshipCrud(MasterDetailCrud):
list_field_names = ['assunto'] list_field_names = ['assunto']
ordering = 'assunto' ordering = 'assunto'
class CreateView(MasterDetailCrud.CreateView):
form_class = AssuntoNormaRelationshipForm
class UpdateView(MasterDetailCrud.UpdateView):
form_class = AssuntoNormaRelationshipForm
class NormaCrud(Crud): class NormaCrud(Crud):
model = NormaJuridica model = NormaJuridica

Loading…
Cancel
Save