From 019d7179a1bd854500d3233035a0b6a7b8686224 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Matheus?= Date: Thu, 28 Mar 2019 17:17:55 -0300 Subject: [PATCH] Fix #2671 --- sapl/sessao/forms.py | 21 +++++++++++++++++++++ sapl/sessao/views.py | 1 + 2 files changed, 22 insertions(+) diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py index c2532b4a1..ece63b83b 100644 --- a/sapl/sessao/forms.py +++ b/sapl/sessao/forms.py @@ -692,7 +692,28 @@ class OradorForm(ModelForm): self.fields['parlamentar'].queryset = Parlamentar.objects.filter( id__in=ids).order_by('nome_parlamentar') + + def clean(self): + super(OradorForm, self).clean() + cleaned_data = self.cleaned_data + + if not self.is_valid(): + return self.cleaned_data + + sessao_id = self.initial['id_sessao'] + numero = self.initial.get('numero') + ordem = Orador.objects.filter( + sessao_plenaria_id=sessao_id, + numero_ordem=cleaned_data['numero_ordem'] + ).exists() + if ordem and (cleaned_data['numero_ordem'] != numero): + raise ValidationError(_( + "Já existe orador nesta posição de ordem de pronunciamento" + )) + + return self.cleaned_data + class Meta: model = Orador exclude = ['sessao_plenaria'] diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 4e4ad02fa..2d4250fa6 100755 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -620,6 +620,7 @@ class OradorCrud(OradorCrud): def get_initial(self): initial = super(UpdateView, self).get_initial() initial.update({'id_sessao': self.object.sessao_plenaria.id}) + initial.update({'numero':self.object.numero_ordem}) return initial