diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py index b54da78bf..a697001af 100644 --- a/sapl/comissoes/forms.py +++ b/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.parlamentares.models import Parlamentar, Legislatura, Mandato - -class ParticipacaoForm(forms.ModelForm): +class ParticipacaoCreateForm(forms.ModelForm): parent_pk = forms.CharField(required=False) # widget=forms.HiddenInput()) class Meta: model = Participacao - # includes = ['parlamentar', 'cargo', 'titular', 'data_designacao', 'data_desligamento', 'data_'] - # exclude = [] exclude = ['composicao'] def __init__(self, user=None, **kwargs): - super(ParticipacaoForm, self).__init__(**kwargs) + super(ParticipacaoCreateForm, self).__init__(**kwargs) if self.instance: comissao = kwargs['initial'] @@ -65,9 +62,7 @@ class ParticipacaoForm(forms.ModelForm): return qs def clean(self): - super(ParticipacaoForm, self).clean() - - # if self.instance: + super(ParticipacaoCreateForm, self).clean() return self.cleaned_data def verifica(self): @@ -95,6 +90,29 @@ class ParticipacaoForm(forms.ModelForm): 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 Meta: @@ -116,7 +134,7 @@ class ComissaoForm(forms.ModelForm): comissao = super(ComissaoForm, self).save(commit) content_type = ContentType.objects.get_for_model(Comissao) object_id = comissao.pk - tipo = TipoAutor.objects.get(descricao='Comissão') + tipo = TipoAutor.objects.get(descricao__icontains='Comiss') nome = comissao.sigla+' - '+comissao.nome Autor.objects.create( content_type=content_type, diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index c84bb6b4a..6c9b0b3b2 100644 --- a/sapl/comissoes/views.py +++ b/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.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.materia.models import MateriaLegislativa, Tramitacao @@ -32,14 +32,13 @@ class ParticipacaoCrud(MasterDetailCrud): parent_field = 'composicao__comissao' public = [RP_DETAIL, ] ListView = None - is_m2m = True link_return_to_parent_field = True class BaseMixin(MasterDetailCrud.BaseMixin): list_field_names = ['composicao', 'parlamentar', 'cargo'] class CreateView(MasterDetailCrud.CreateView): - form_class = ParticipacaoForm + form_class = ParticipacaoCreateForm def get_initial(self): initial = super().get_initial() @@ -47,12 +46,17 @@ class ParticipacaoCrud(MasterDetailCrud): return initial 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): diff --git a/sapl/templates/comissoes/layouts.yaml b/sapl/templates/comissoes/layouts.yaml index bb4759211..b5e856b2e 100644 --- a/sapl/templates/comissoes/layouts.yaml +++ b/sapl/templates/comissoes/layouts.yaml @@ -36,3 +36,10 @@ Participacao: - data_designacao data_desligamento - motivo_desligamento - observacao + +ParticipacaoEdit: + {% trans 'Participação' %}: + - nome_parlamentar cargo titular + - data_designacao data_desligamento + - motivo_desligamento + - observacao \ No newline at end of file