From daae2470ad0d618eba30a53635e251569aee781b Mon Sep 17 00:00:00 2001 From: eribeiro Date: Wed, 3 Mar 2021 15:01:38 -0300 Subject: [PATCH] HOT-FIX: Mais bugs em Bancada/Bloco --- sapl/parlamentares/forms.py | 54 ++++++++++++++++++++++--------------- sapl/parlamentares/views.py | 6 +++++ sapl/sessao/forms.py | 25 ++++++++++------- sapl/sessao/views.py | 6 +++++ 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index d8ba0c3c8..f7c813188 100755 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -324,17 +324,22 @@ class ParlamentarCreateForm(ParlamentarForm): return cleaned_data @transaction.atomic - def save(self, commit=True): + def save(self, commit=False): parlamentar = super(ParlamentarCreateForm, self).save(commit) - content_type = ContentType.objects.get_for_model(Parlamentar) - object_id = parlamentar.pk - tipo = TipoAutor.objects.get(content_type=content_type) - Autor.objects.create( - content_type=content_type, - object_id=object_id, - tipo=tipo, - nome=parlamentar.nome_parlamentar - ) + + if not self.instance.pk: + parlamentar.save() + content_type = ContentType.objects.get_for_model(Parlamentar) + object_id = parlamentar.pk + tipo = TipoAutor.objects.get(content_type=content_type) + Autor.objects.create( + content_type=content_type, + object_id=object_id, + tipo=tipo, + nome=parlamentar.nome_parlamentar + ) + else: + parlamentar.save() return parlamentar @@ -495,11 +500,11 @@ class FrenteForm(ModelForm): return cd @transaction.atomic - def save(self, commit=True): + def save(self, commit=False): frente = super(FrenteForm, self).save(commit) if not self.instance.pk: - frente = super(FrenteForm, self).save(commit) + frente.save() content_type = ContentType.objects.get_for_model(Frente) object_id = frente.pk tipo = TipoAutor.objects.get(descricao__icontains='Frente') @@ -509,6 +514,8 @@ class FrenteForm(ModelForm): tipo=tipo, nome=frente.nome ) + else: + frente.save() return frente @@ -693,16 +700,19 @@ class BlocoForm(ModelForm): @transaction.atomic def save(self, commit=False): bloco = super(BlocoForm, self).save(commit) - bloco.save() - content_type = ContentType.objects.get_for_model(Bloco) - object_id = bloco.pk - tipo = TipoAutor.objects.get(content_type=content_type) - Autor.objects.create( - content_type=content_type, - object_id=object_id, - tipo=tipo, - nome=bloco.nome - ) + if not self.instance.pk: + bloco.save() + content_type = ContentType.objects.get_for_model(Bloco) + object_id = bloco.pk + tipo = TipoAutor.objects.get(content_type=content_type) + Autor.objects.create( + content_type=content_type, + object_id=object_id, + tipo=tipo, + nome=bloco.nome + ) + else: + bloco.save() return bloco diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index d65f3f395..b8b2755e9 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -1282,6 +1282,12 @@ class BlocoCrud(CrudAux): def get_success_url(self): return reverse('sapl.parlamentares:bloco_list') + class UpdateView(CrudAux.UpdateView): + form_class = BlocoForm + + def get_success_url(self): + return reverse('sapl.parlamentares:bloco_list') + class BlocoMembroCrud(MasterDetailCrud): model = BlocoMembro diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py index ba10e5b2a..cbfcbb2e4 100644 --- a/sapl/sessao/forms.py +++ b/sapl/sessao/forms.py @@ -266,17 +266,22 @@ class BancadaForm(ModelForm): return self.cleaned_data @transaction.atomic - def save(self, commit=True): + def save(self, commit=False): bancada = super(BancadaForm, self).save(commit) - content_type = ContentType.objects.get_for_model(Bancada) - object_id = bancada.pk - tipo = TipoAutor.objects.get(content_type=content_type) - Autor.objects.create( - content_type=content_type, - object_id=object_id, - tipo=tipo, - nome=bancada.nome - ) + + if not self.instance.pk: + bancada.save() + content_type = ContentType.objects.get_for_model(Bancada) + object_id = bancada.pk + tipo = TipoAutor.objects.get(content_type=content_type) + Autor.objects.create( + content_type=content_type, + object_id=object_id, + tipo=tipo, + nome=bancada.nome + ) + else: + bancada.save() return bancada diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index b1dc4b067..a70dc322b 100755 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -1113,6 +1113,12 @@ class BancadaCrud(CrudAux): def get_success_url(self): return reverse('sapl.sessao:bancada_list') + class UpdateView(CrudAux.UpdateView): + form_class = BancadaForm + + def get_success_url(self): + return reverse('sapl.sessao:bancada_list') + def recuperar_numero_sessao_view(request): try: