Browse Source

1694 corrige edicao participacao (#1696)

* Fix

* Fix #1694

* Ajuste de limite horizontal
pull/1698/head
VictorFabreF 7 years ago
committed by Edward
parent
commit
5c270e7ca5
  1. 36
      sapl/comissoes/forms.py
  2. 20
      sapl/comissoes/views.py
  3. 7
      sapl/templates/comissoes/layouts.yaml

36
sapl/comissoes/forms.py

@ -9,19 +9,16 @@ from sapl.base.models import Autor, TipoAutor
from sapl.comissoes.models import Participacao, Composicao, Comissao from sapl.comissoes.models import Participacao, Composicao, Comissao
from sapl.parlamentares.models import Parlamentar, Legislatura, Mandato from sapl.parlamentares.models import Parlamentar, Legislatura, Mandato
class ParticipacaoCreateForm(forms.ModelForm):
class ParticipacaoForm(forms.ModelForm):
parent_pk = forms.CharField(required=False) # widget=forms.HiddenInput()) parent_pk = forms.CharField(required=False) # widget=forms.HiddenInput())
class Meta: class Meta:
model = Participacao model = Participacao
# includes = ['parlamentar', 'cargo', 'titular', 'data_designacao', 'data_desligamento', 'data_']
# exclude = []
exclude = ['composicao'] exclude = ['composicao']
def __init__(self, user=None, **kwargs): def __init__(self, user=None, **kwargs):
super(ParticipacaoForm, self).__init__(**kwargs) super(ParticipacaoCreateForm, self).__init__(**kwargs)
if self.instance: if self.instance:
comissao = kwargs['initial'] comissao = kwargs['initial']
@ -65,9 +62,7 @@ class ParticipacaoForm(forms.ModelForm):
return qs return qs
def clean(self): def clean(self):
super(ParticipacaoForm, self).clean() super(ParticipacaoCreateForm, self).clean()
# if self.instance:
return self.cleaned_data return self.cleaned_data
def verifica(self): def verifica(self):
@ -95,6 +90,29 @@ class ParticipacaoForm(forms.ModelForm):
return lista return lista
class ParticipacaoEditForm(forms.ModelForm):
parent_pk = forms.CharField(required=False) # widget=forms.HiddenInput())
nome_parlamentar = forms.CharField(required=False, label='Parlamentar')
class Meta:
model = Participacao
fields = ['nome_parlamentar', 'parlamentar', 'cargo', 'titular',
'data_designacao', 'data_desligamento',
'motivo_desligamento', 'observacao']
widgets = {
'parlamentar': forms.HiddenInput(),
}
def __init__(self, user=None, **kwargs):
super(ParticipacaoEditForm, self).__init__(**kwargs)
self.initial['nome_parlamentar'] = Parlamentar.objects.get(
id=self.initial['parlamentar']).nome_parlamentar
self.fields['nome_parlamentar'].widget.attrs['disabled'] = 'disabled'
class ComissaoForm(forms.ModelForm): class ComissaoForm(forms.ModelForm):
class Meta: class Meta:
@ -116,7 +134,7 @@ class ComissaoForm(forms.ModelForm):
comissao = super(ComissaoForm, self).save(commit) comissao = super(ComissaoForm, self).save(commit)
content_type = ContentType.objects.get_for_model(Comissao) content_type = ContentType.objects.get_for_model(Comissao)
object_id = comissao.pk object_id = comissao.pk
tipo = TipoAutor.objects.get(descricao='Comissão') tipo = TipoAutor.objects.get(descricao__icontains='Comiss')
nome = comissao.sigla+' - '+comissao.nome nome = comissao.sigla+' - '+comissao.nome
Autor.objects.create( Autor.objects.create(
content_type=content_type, content_type=content_type,

20
sapl/comissoes/views.py

@ -4,7 +4,7 @@ from django.db.models import F
from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import ListView from django.views.generic import ListView
from sapl.comissoes.forms import ParticipacaoForm from sapl.comissoes.forms import ParticipacaoCreateForm, ParticipacaoEditForm
from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, CrudAux, MasterDetailCrud from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, CrudAux, MasterDetailCrud
from sapl.materia.models import MateriaLegislativa, Tramitacao from sapl.materia.models import MateriaLegislativa, Tramitacao
@ -32,14 +32,13 @@ class ParticipacaoCrud(MasterDetailCrud):
parent_field = 'composicao__comissao' parent_field = 'composicao__comissao'
public = [RP_DETAIL, ] public = [RP_DETAIL, ]
ListView = None ListView = None
is_m2m = True
link_return_to_parent_field = True link_return_to_parent_field = True
class BaseMixin(MasterDetailCrud.BaseMixin): class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['composicao', 'parlamentar', 'cargo'] list_field_names = ['composicao', 'parlamentar', 'cargo']
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = ParticipacaoForm form_class = ParticipacaoCreateForm
def get_initial(self): def get_initial(self):
initial = super().get_initial() initial = super().get_initial()
@ -47,12 +46,17 @@ class ParticipacaoCrud(MasterDetailCrud):
return initial return initial
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = ParticipacaoForm layout_key = 'ParticipacaoEdit'
form_class = ParticipacaoEditForm
class DeleteView(MasterDetailCrud.DeleteView):
def get_success_url(self):
composicao_comissao_pk = self.object.composicao.comissao.pk
composicao_pk = self.object.composicao.pk
return '{}?pk={}'.format(reverse('sapl.comissoes:composicao_list',
args=[composicao_comissao_pk]),
)
def get_initial(self):
initial = super().get_initial()
initial['parent_pk'] = self.kwargs['pk']
return initial
class ComposicaoCrud(MasterDetailCrud): class ComposicaoCrud(MasterDetailCrud):

7
sapl/templates/comissoes/layouts.yaml

@ -36,3 +36,10 @@ Participacao:
- data_designacao data_desligamento - data_designacao data_desligamento
- motivo_desligamento - motivo_desligamento
- observacao - observacao
ParticipacaoEdit:
{% trans 'Participação' %}:
- nome_parlamentar cargo titular
- data_designacao data_desligamento
- motivo_desligamento
- observacao
Loading…
Cancel
Save