From 94c0a7190fc8ee43b4a34dbf09bafe858bcd4e46 Mon Sep 17 00:00:00 2001 From: Talitha Pumar Date: Fri, 13 Apr 2018 12:28:51 -0300 Subject: [PATCH] Fix #1856 (#1866) --- sapl/comissoes/forms.py | 8 +++++++- sapl/comissoes/views.py | 4 ++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py index 0a3718b1d..3576873b7 100644 --- a/sapl/comissoes/forms.py +++ b/sapl/comissoes/forms.py @@ -13,10 +13,16 @@ from sapl.parlamentares.models import Legislatura, Mandato, Parlamentar class ComposicaoForm(forms.ModelForm): + comissao = forms.CharField(required=False, label='Comissao', widget=forms.HiddenInput()) + class Meta: model = Composicao exclude = [] + def __init__(self, user=None, **kwargs): + super(ComposicaoForm, self).__init__(**kwargs) + self.fields['comissao'].widget.attrs['disabled'] = 'disabled' + def clean(self): cleaned_data = super(ComposicaoForm, self).clean() @@ -24,7 +30,7 @@ class ComposicaoForm(forms.ModelForm): return cleaned_data periodo = cleaned_data['periodo'] - comissao_pk = cleaned_data['comissao'].id + comissao_pk = self.initial['comissao'].id intersecao_periodo = Composicao.objects.filter( Q(periodo__data_inicio__lte=periodo.data_fim, periodo__data_fim__gte=periodo.data_fim) | diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 6c47ac6e1..82c3a79c1 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -90,6 +90,10 @@ class ComposicaoCrud(MasterDetailCrud): class CreateView(MasterDetailCrud.CreateView): form_class = ComposicaoForm + + def get_initial(self): + comissao = Comissao.objects.get(id=self.kwargs['pk']) + return {'comissao': comissao} class ListView(MasterDetailCrud.ListView):