From bffe5fc15fb5d73d52bc524a2934b65f8ab4acd9 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Fri, 11 Aug 2017 19:41:56 -0300 Subject: [PATCH] Fixes #1400 --- sapl/sessao/forms.py | 32 ++++++++++++++++++++++++++++++++ sapl/sessao/views.py | 6 +++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py index 91881b32c..c617364bc 100644 --- a/sapl/sessao/forms.py +++ b/sapl/sessao/forms.py @@ -51,6 +51,38 @@ ORDENACAO_RESUMO = [('cont_mult', 'Conteúdo Multimídia'), ('oradores_exped', 'Oradores do Expediente'), ('oradores_expli', 'Oradores das Explicações Pessoais')] +class SessaoPlenariaForm(ModelForm): + + class Meta: + model = SessaoPlenaria + exclude = ['cod_andamento_sessao'] + + def clean(self): + super(SessaoPlenariaForm, self).clean() + + instance = self.instance + + num = self.cleaned_data['numero'] + sl = self.cleaned_data['sessao_legislativa'] + leg = self.cleaned_data['legislatura'] + + sessoes = SessaoPlenaria.objects.filter(numero=num, + sessao_legislativa=sl, + legislatura=leg).\ + values_list('id', flat=True) + + qtd_sessoes = len(sessoes) + + error = ValidationError('Número de Sessão Plenária Existente') + + if qtd_sessoes > 0: + if instance.pk: # update + if not instance.pk in sessoes or qtd_sessoes > 1: + raise error + else: # create + raise error + + return self.cleaned_data class BancadaForm(ModelForm): diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index f72f803e1..fb44472c9 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -37,7 +37,7 @@ from sapl.sessao.forms import ExpedienteMateriaForm, OrdemDiaForm from .forms import (AdicionarVariasMateriasFilterSet, ExpedienteForm, ListMateriaForm, MesaForm, OradorExpedienteForm, OradorForm, PautaSessaoFilterSet, PresencaForm, - ResumoOrdenacaoForm, SessaoPlenariaFilterSet, + ResumoOrdenacaoForm, SessaoPlenariaFilterSet, SessaoPlenariaForm, VotacaoEditForm, VotacaoForm, VotacaoNominalForm) from .models import (Bancada, Bloco, CargoBancada, CargoMesa, ExpedienteMateria, ExpedienteSessao, IntegranteMesa, @@ -542,11 +542,15 @@ class SessaoCrud(Crud): class UpdateView(Crud.UpdateView): + form_class = SessaoPlenariaForm + def get_initial(self): return {'sessao_legislativa': self.object.sessao_legislativa} class CreateView(Crud.CreateView): + form_class = SessaoPlenariaForm + @property def cancel_url(self): return self.search_url