Repository: interlegis/sapl

Issue:
Corrigir edição e criação de participação em comissão



Discussion:

Resolving patch:
diff --git a/sapl/comissoes/forms.py b/sapl/comissoes/forms.py
--- a/sapl/comissoes/forms.py
+++ b/sapl/comissoes/forms.py
@@ -9,19 +9,16 @@
 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 @@ def create_participacao(self):
         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 @@ def verifica(self):
 
         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 @@ 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='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
--- a/sapl/comissoes/views.py
+++ b/sapl/comissoes/views.py
@@ -4,7 +4,7 @@
 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 @@ def get_initial(self):
             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):


Test patch: