From c78dd48779af767d9b00eefcab7eb2908a0d437f Mon Sep 17 00:00:00 2001 From: Edward Date: Tue, 3 Apr 2018 16:37:52 -0300 Subject: [PATCH] Fix #1820 - checa se data inicio > data_fim para periodo de comissao (#1822) --- sapl/comissoes/forms.py | 18 +++++++++++++++++- sapl/comissoes/views.py | 13 ++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py index 66e8280cf..125b2599c 100644 --- a/sapl/comissoes/forms.py +++ b/sapl/comissoes/forms.py @@ -8,7 +8,7 @@ from django.utils.translation import ugettext_lazy as _ from sapl.base.models import Autor, TipoAutor from sapl.comissoes.models import (Comissao, Composicao, DocumentoAcessorio, - Participacao, Reuniao) + Participacao, Reuniao, Periodo) from sapl.parlamentares.models import Legislatura, Mandato, Parlamentar class ComposicaoForm(forms.ModelForm): @@ -39,6 +39,22 @@ class ComposicaoForm(forms.ModelForm): return cleaned_data +class PeriodoForm(forms.ModelForm): + + class Meta: + model = Periodo + exclude = [] + + def clean(self): + cleaned_data = super(PeriodoForm, self).clean() + data_inicio = cleaned_data['data_inicio'] + data_fim = cleaned_data['data_fim'] + + if data_fim and data_fim < data_inicio: + raise ValidationError('Data início não pode ser superior a data de fim') + return cleaned_data + + class ParticipacaoCreateForm(forms.ModelForm): parent_pk = forms.CharField(required=False) # widget=forms.HiddenInput()) diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 8ae56ffd6..6c47ac6e1 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -13,9 +13,9 @@ from sapl.base.models import AppConfig as AppsAppConfig from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, MasterDetailCrud, PermissionRequiredForAppCrudMixin) -from sapl.comissoes.forms import (ComissaoForm,ComposicaoForm, DocumentoAcessorioCreateForm, +from sapl.comissoes.forms import (ComissaoForm, ComposicaoForm, DocumentoAcessorioCreateForm, DocumentoAcessorioEditForm, ParticipacaoCreateForm, - ParticipacaoEditForm, ReuniaoForm) + ParticipacaoEditForm, ReuniaoForm, PeriodoForm) from sapl.materia.models import MateriaLegislativa, Tramitacao @@ -37,12 +37,19 @@ def pegar_url_reuniao(pk): return url CargoCrud = CrudAux.build(CargoComissao, 'cargo_comissao') -PeriodoComposicaoCrud = CrudAux.build(Periodo, 'periodo_composicao_comissao') TipoComissaoCrud = CrudAux.build( TipoComissao, 'tipo_comissao', list_field_names=[ 'sigla', 'nome', 'natureza', 'dispositivo_regimental']) +class PeriodoComposicaoCrud(CrudAux): + model = Periodo + + class CreateView(CrudAux.CreateView): + form_class = PeriodoForm + + class UpdateView(CrudAux.UpdateView): + form_class = PeriodoForm class ParticipacaoCrud(MasterDetailCrud): model = Participacao