From de67f6c8aa879d5d3f64fa31d69ef482c676158a Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 10 Feb 2017 09:20:04 -0200 Subject: [PATCH] Delete user --- sapl/parlamentares/forms.py | 1 - sapl/parlamentares/views.py | 11 +++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index bd9846a5e..210f2a7b8 100644 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -309,7 +309,6 @@ class VotanteForm(ModelForm): def save(self, commit=False): votante = super(VotanteForm, self).save(commit) - u = User.objects.get(username=self.cleaned_data['username']) u = User.objects.create( username=self.cleaned_data['username'], email=self.cleaned_data['email']) diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 874e1b23d..366a08715 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -4,6 +4,7 @@ from django.core.urlresolvers import reverse, reverse_lazy from django.utils.datastructures import MultiValueDictKeyError from django.utils.translation import ugettext_lazy as _ from django.views.generic import FormView +from django.http.response import HttpResponseRedirect from sapl.comissoes.models import Participacao from sapl.crud.base import (RP_CHANGE, RP_DETAIL, RP_LIST, Crud, CrudAux, @@ -57,6 +58,16 @@ class VotanteView(MasterDetailCrud): def detail_create_url(self): return None + class DeleteView(MasterDetailCrud.DeleteView): + + def delete(self, *args, **kwargs): + obj = self.get_object() + if obj.user: + obj.user.delete() + return HttpResponseRedirect( + reverse('sapl.parlamentares:votante_list', + kwargs={'pk': obj.parlamentar.pk})) + class FrenteList(MasterDetailCrud): model = Frente