Browse Source

Fix #1791 (#1805)

pull/1815/head
Victor Fabre 7 years ago
committed by Edward Ribeiro
parent
commit
287abf7e02
  1. 42
      sapl/comissoes/forms.py
  2. 6
      sapl/comissoes/views.py

42
sapl/comissoes/forms.py

@ -161,6 +161,19 @@ class ComissaoForm(forms.ModelForm):
model = Comissao model = Comissao
fields = '__all__' 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): def clean(self):
super(ComissaoForm, self).clean() super(ComissaoForm, self).clean()
@ -176,18 +189,23 @@ class ComissaoForm(forms.ModelForm):
@transaction.atomic @transaction.atomic
def save(self, commit=True): def save(self, commit=True):
comissao = super(ComissaoForm, self).save(commit) inst = self.instance
content_type = ContentType.objects.get_for_model(Comissao) if not inst.pk:
object_id = comissao.pk comissao = super(ComissaoForm, self).save(commit)
tipo = TipoAutor.objects.get(descricao__icontains='Comiss') content_type = ContentType.objects.get_for_model(Comissao)
nome = comissao.sigla + ' - ' + comissao.nome object_id = comissao.pk
Autor.objects.create( tipo = TipoAutor.objects.get(descricao__icontains='Comiss')
content_type=content_type, nome = comissao.sigla + ' - ' + comissao.nome
object_id=object_id, Autor.objects.create(
tipo=tipo, content_type=content_type,
nome=nome object_id=object_id,
) tipo=tipo,
return comissao nome=nome
)
return comissao
else:
comissao = super(ComissaoForm, self).save(commit)
return comissao
class ReuniaoForm(ModelForm): class ReuniaoForm(ModelForm):

6
sapl/comissoes/views.py

@ -131,6 +131,12 @@ class ComissaoCrud(Crud):
def form_valid(self, form): def form_valid(self, form):
return super(Crud.CreateView, self).form_valid(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): class MateriasTramitacaoListView(ListView):
template_name = "comissoes/materias_em_tramitacao.html" template_name = "comissoes/materias_em_tramitacao.html"

Loading…
Cancel
Save