From d36c6d32a6c2bf3d4f9f72e39dd3440f857e7ded Mon Sep 17 00:00:00 2001 From: "tapumar@gmail.com" Date: Fri, 10 Aug 2018 12:21:59 -0100 Subject: [PATCH] Fix #2127 Checagem de datas de Frente Parlamentar e coluna extra na listagem --- sapl/parlamentares/forms.py | 32 +++++++++++++++++++++++--------- sapl/parlamentares/views.py | 12 ++++++++---- 2 files changed, 31 insertions(+), 13 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..a48e95833 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) @@ -278,11 +277,12 @@ def parlamentares_frente_selected(request): return JsonResponse({'id_list': list(lista_parlamentar_id)}) -class FrenteCrud(CrudAux): +class FrenteCrud(Crud): 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