From dd8f3b5ecd75db44549a970f6af0522e944de7e8 Mon Sep 17 00:00:00 2001 From: Victor Fabre Date: Wed, 28 Mar 2018 10:54:52 -0300 Subject: [PATCH] Fix #1791 (#1805) --- sapl/comissoes/forms.py | 42 +++++++++++++++++++++++++++++------------ sapl/comissoes/views.py | 6 ++++++ 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py index 4ccc52c27..c642d978c 100644 --- a/sapl/comissoes/forms.py +++ b/sapl/comissoes/forms.py @@ -161,6 +161,19 @@ class ComissaoForm(forms.ModelForm): model = Comissao fields = '__all__' + def __init__(self, user=None, **kwargs): + super(ComissaoForm, self).__init__(**kwargs) + inst = self.instance + if inst.pk: + if inst.tipo.natureza == 'P': + self.fields['apelido_temp'].widget.attrs['disabled'] = 'disabled' + self.fields['data_instalacao_temp'].widget.attrs['disabled'] = 'disabled' + self.fields['data_final_prevista_temp'].widget.attrs['disabled'] = 'disabled' + self.fields['data_prorrogada_temp'].widget.attrs['disabled'] = 'disabled' + self.fields['data_fim_comissao'].widget.attrs['disabled'] = 'disabled' + + + def clean(self): super(ComissaoForm, self).clean() @@ -176,18 +189,23 @@ class ComissaoForm(forms.ModelForm): @transaction.atomic def save(self, commit=True): - comissao = super(ComissaoForm, self).save(commit) - content_type = ContentType.objects.get_for_model(Comissao) - object_id = comissao.pk - tipo = TipoAutor.objects.get(descricao__icontains='Comiss') - nome = comissao.sigla + ' - ' + comissao.nome - Autor.objects.create( - content_type=content_type, - object_id=object_id, - tipo=tipo, - nome=nome - ) - return comissao + inst = self.instance + if not inst.pk: + comissao = super(ComissaoForm, self).save(commit) + content_type = ContentType.objects.get_for_model(Comissao) + object_id = comissao.pk + tipo = TipoAutor.objects.get(descricao__icontains='Comiss') + nome = comissao.sigla + ' - ' + comissao.nome + Autor.objects.create( + content_type=content_type, + object_id=object_id, + tipo=tipo, + nome=nome + ) + return comissao + else: + comissao = super(ComissaoForm, self).save(commit) + return comissao class ReuniaoForm(ModelForm): diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index 2f1d2dad7..8ae56ffd6 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -131,6 +131,12 @@ class ComissaoCrud(Crud): def form_valid(self, form): return super(Crud.CreateView, self).form_valid(form) + class UpdateView(Crud.UpdateView): + form_class = ComissaoForm + + def form_valid(self, form): + return super(Crud.UpdateView, self).form_valid(form) + class MateriasTramitacaoListView(ListView): template_name = "comissoes/materias_em_tramitacao.html"