From 217a4a0e1e7cbc321fb98827d9bc767bda8b7d46 Mon Sep 17 00:00:00 2001 From: Talitha Pumar Date: Fri, 10 Aug 2018 15:58:18 -0100 Subject: [PATCH] =?UTF-8?q?Fix=20#2127=20Checagem=20de=20datas=20de=20Fren?= =?UTF-8?q?te=20Parlamentar=20e=20coluna=20extra=20na=20l=E2=80=A6=20(#213?= =?UTF-8?q?1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #2127 Checagem de datas de Frente Parlamentar e coluna extra na listagem * Update views.py --- sapl/parlamentares/forms.py | 32 +++++++++++++++++++++++--------- sapl/parlamentares/views.py | 10 +++++++--- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index 36ce94c3a..d112e1d81 100644 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -318,18 +318,32 @@ class FrenteForm(ModelForm): model = Frente fields = '__all__' + def clean(self): + frente = super(FrenteForm, self).clean() + cd = self.cleaned_data + if not self.is_valid(): + return self.cleaned_data + + if cd['data_criacao'] >= cd['data_extincao']: + raise ValidationError(_("Data Dissolução não pode ser anterior a Data Criação")) + + return cd + @transaction.atomic def save(self, commit=True): frente = super(FrenteForm, self).save(commit) - content_type = ContentType.objects.get_for_model(Frente) - object_id = frente.pk - tipo = TipoAutor.objects.get(descricao__icontains='Frente') - Autor.objects.create( - content_type=content_type, - object_id=object_id, - tipo=tipo, - nome=frente.nome - ) + + if not self.instance.pk: + frente = super(FrenteForm, self).save(commit) + content_type = ContentType.objects.get_for_model(Frente) + object_id = frente.pk + tipo = TipoAutor.objects.get(descricao__icontains='Frente') + Autor.objects.create( + content_type=content_type, + object_id=object_id, + tipo=tipo, + nome=frente.nome + ) return frente diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 78678c3fc..ad4a8f5e5 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -87,8 +87,7 @@ class FrenteList(MasterDetailCrud): CreateView, UpdateView, DeleteView = None, None, None class BaseMixin(Crud.PublicMixin, MasterDetailCrud.BaseMixin): - list_field_names = ['nome', 'data_criacao'] - + list_field_names = ['nome', 'data_criacao', 'data_extincao'] @classmethod def url_name(cls, suffix): return '%s_parlamentar_%s' % (cls.model._meta.model_name, suffix) @@ -282,7 +281,8 @@ class FrenteCrud(CrudAux): model = Frente help_topic = 'tipo_situa_militar' public = [RP_DETAIL, RP_LIST] - list_field_names = ['nome', 'data_criacao', 'parlamentares'] + list_field_names = ['nome', 'data_criacao', 'data_extincao', 'parlamentares'] + class CreateView(Crud.CreateView): form_class = FrenteForm @@ -290,6 +290,10 @@ class FrenteCrud(CrudAux): def form_valid(self, form): return super(Crud.CreateView, self).form_valid(form) + class UpdateView(Crud.UpdateView): + form_class = FrenteForm + + class MandatoCrud(MasterDetailCrud): model = Mandato