From c416825f1bb19906cb0d9082e8422561f0baf208 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 3 May 2016 10:58:11 -0300 Subject: [PATCH] =?UTF-8?q?Termina=20valida=C3=A7=C3=B5es=20para=20deletar?= =?UTF-8?q?=20uma=20tramita=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/views.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/materia/views.py b/materia/views.py index 7e373774e..d199850a5 100644 --- a/materia/views.py +++ b/materia/views.py @@ -81,15 +81,19 @@ class TramitacaoCrud(MasterDetailCrud): class DeleteView(MasterDetailCrud.DeleteView): def delete(self, request, *args, **kwargs): - tramitacao = Tramitacao.objects.get( - id=self.kwargs['pk']) + tramitacao = Tramitacao.objects.get(id=self.kwargs['pk']) materia = MateriaLegislativa.objects.get(id=tramitacao.materia.id) + url = reverse('materia:tramitacao_list', + kwargs={'pk': tramitacao.materia.id}) + if tramitacao.pk != materia.tramitacao_set.last().pk: - msg = _('Somente a útlima tramitação pode ser deletada!') - raise ValidationError(msg) + msg = _('Somente a útlima tramitação pode ser deletada!') + # raise ValidationError(msg) + messages.add_message(request, messages.ERROR, msg) + return HttpResponseRedirect(url) else: - self.get_object().delete() - return HttpResponseRedirect(self.cancel_url()) + tramitacao.delete() + return HttpResponseRedirect(url) class AutoriaCrud(MasterDetailCrud):