diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 21c171c68..4e2e6b4a8 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -343,6 +343,13 @@ class MesaDiretoraView(FormView): 'cargos_vagos': cargos_vagos }) + def existe_membro_mesa(self, sessao_plenaria, cargo): + return ComposicaoMesa.objects.filter( + sessao_legislativa_id=sessao_plenaria.id, + #parlamentar_id = integrante.parlamentar_id, + cargo_id = cargo.id + ).exists() + def post(self, request, *args, **kwargs): if (not Legislatura.objects.exists() or @@ -374,6 +381,11 @@ class MesaDiretoraView(FormView): try: composicao.cargo = CargoMesa.objects.get( id=int(request.POST['cargo'])) + if self.existe_membro_mesa(composicao.sessao_legislativa, + composicao.cargo): + messages.error(request, _('Parlamentar já inserido!')) + return self.get(request) + composicao.save() except MultiValueDictKeyError: messages.error(request, _( diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index 3ccd0f4b0..2e63bc286 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -808,7 +808,6 @@ class MesaView(FormMixin, DetailView): integrante.parlamentar_id = request.POST['parlamentar'] integrante.cargo_id = request.POST['cargo'] integrante.save() - return self.form_valid(form) else: