From bb463c923c8a02a93cde4e2ebf27ccdd35a36e31 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 18 Nov 2015 12:52:33 -0200 Subject: [PATCH] =?UTF-8?q?Fix=20successful=20return=20from=20Protocolar?= =?UTF-8?q?=20Doc=20Adm=20e=20Protocolar=20Mat=C3=A9ria?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocoloadm/views.py | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index f15db09fa..e512409d0 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -335,10 +335,7 @@ class AnularProtocoloAdmView(FormMixin, GenericView): protocolo.user_anulacao = user_anulacao protocolo.ip_anulacao = ip_addr protocolo.save() - message = "Protocolo criado com sucesso" - return render(request, - reverse("anular_protocolo"), - {'form': form, 'message': message}) + return self.form_valid(form) except ObjectDoesNotExist: errors = form._errors.setdefault( @@ -387,7 +384,7 @@ class ProtocoloDocumentoView(FormMixin, GenericView): model = Protocolo def get_success_url(self): - return reverse('protocolar_doc') + return reverse('protocolo') def get(self, request, *args, **kwargs): form = ProtocoloDocumentForm() @@ -398,15 +395,12 @@ class ProtocoloDocumentoView(FormMixin, GenericView): form = ProtocoloDocumentForm(request.POST) if form.is_valid(): - if request.POST['numeracao'] == '1': numeracao = Protocolo.objects.filter( ano=date.today().year).aggregate(Max('numero')) else: numeracao = Protocolo.objects.all().aggregate(Max('numero')) - protocolo = Protocolo() - protocolo.numero = numeracao['numero__max'] + 1 protocolo.ano = datetime.now().year protocolo.data = datetime.now().strftime("%Y-%m-%d") @@ -423,13 +417,7 @@ class ProtocoloDocumentoView(FormMixin, GenericView): protocolo.numero_paginas = request.POST['num_paginas'] protocolo.observacao = sub( ' ', ' ', strip_tags(request.POST['observacao'])) - - protocolo.save() - - message = "Protocolo criado com sucesso" - return render(request, - reverse('protocolo'), - {'form': form, 'message': message}) + return self.form_valid(form) else: return self.form_invalid(form) @@ -516,10 +504,7 @@ class ProtocoloMateriaView(FormMixin, GenericView): protocolo.save() - message = "Protocolo criado com sucesso" - return render(request, - reverse('protocolo'), - {'form': form, 'message': message}) + return self.form_valid(form) else: return self.form_invalid(form)