From 092c30c210b1a022fdc8a112d4c653a58e0f6ecd Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Thu, 7 Nov 2019 15:39:39 -0300 Subject: [PATCH] HOT-FIX: refatora mandato. --- sapl/parlamentares/forms.py | 8 ++++++-- sapl/parlamentares/views.py | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index 576160ff6..448535d40 100755 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -140,8 +140,12 @@ class MandatoForm(ModelForm): existe_mandato = Mandato.objects.filter( parlamentar=data['parlamentar'], - legislatura=data['legislatura']).exists() - if existe_mandato and data['titular']: + legislatura=data['legislatura']) + + if self.instance.pk: + existe_mandato = existe_mandato.exclude(id=self.instance.pk) + + if existe_mandato.exists() and data['titular']: self.logger.error("Mandato nesta legislatura (parlamentar={}, legislatura={}) já existe." .format(data['parlamentar'], data['legislatura'])) raise ValidationError(_('Mandato nesta legislatura já existe.')) diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index af16dd6df..4adf325f6 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -427,6 +427,9 @@ class MandatoCrud(MasterDetailCrud): return {'parlamentar': Parlamentar.objects.get( pk=self.kwargs['pk'])} + class UpdateView(MasterDetailCrud.UpdateView): + form_class = MandatoForm + class ComposicaoColigacaoCrud(MasterDetailCrud): model = ComposicaoColigacao