From b6d42cc50b7e548e6ebbe3cf64058b61db8ac240 Mon Sep 17 00:00:00 2001 From: Mariana Mendes Date: Tue, 21 Aug 2018 13:03:31 -0300 Subject: [PATCH] FIX #2129 (#2146) * fix #2129 * fix #2129 * fix #2129 * fix #2129 --- sapl/comissoes/forms.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py index fc81b3510..b9af7d0ee 100644 --- a/sapl/comissoes/forms.py +++ b/sapl/comissoes/forms.py @@ -45,6 +45,7 @@ class ComposicaoForm(forms.ModelForm): return cleaned_data + class PeriodoForm(forms.ModelForm): class Meta: @@ -63,9 +64,20 @@ class PeriodoForm(forms.ModelForm): if data_fim and data_fim < data_inicio: raise ValidationError('A Data Final não pode ser menor que ' 'a Data Inicial') + + legislatura = Legislatura.objects.filter(data_inicio__lte=data_inicio, + data_fim__gte=data_fim) + + if not legislatura: + raise ValidationError('O período informado ' + 'deve estar contido em uma única ' + 'legislatura existente') + + return cleaned_data + class ParticipacaoCreateForm(forms.ModelForm): parent_pk = forms.CharField(required=False) # widget=forms.HiddenInput())