Browse Source

Teste delete

pull/380/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
c146a931a9
  1. 15
      materia/views.py

15
materia/views.py

@ -4,7 +4,7 @@ from random import choice
from string import ascii_letters, digits
from django.contrib import messages
from django.core.exceptions import ObjectDoesNotExist
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.mail import send_mail
from django.core.urlresolvers import reverse
from django.http.response import HttpResponseRedirect
@ -78,6 +78,19 @@ class TramitacaoCrud(MasterDetailCrud):
kwargs = {self.crud.parent_field: self.kwargs['pk']}
return qs.filter(**kwargs).order_by('-data_tramitacao')
class DeleteView(MasterDetailCrud.DeleteView):
def delete(self, request, *args, **kwargs):
tramitacao = Tramitacao.objects.get(
id=self.kwargs['pk'])
materia = MateriaLegislativa.objects.get(id=tramitacao.materia.id)
if tramitacao.pk != materia.tramitacao_set.last().pk:
msg = _('Somente a útlima tramitação pode ser deletada!')
raise ValidationError(msg)
else:
self.get_object().delete()
return HttpResponseRedirect(self.cancel_url())
class AutoriaCrud(MasterDetailCrud):
model = Autoria

Loading…
Cancel
Save