From 81c9ac90a6442a3140b0d8fe66d6d1b6f055c162 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 10 Feb 2017 10:45:59 -0200 Subject: [PATCH] Adiciona grupo ao usuario parlamentar --- sapl/parlamentares/forms.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index 210f2a7b8..73e4f90a4 100644 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -1,4 +1,5 @@ from datetime import date, timedelta +from django.contrib.auth.models import Group from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout @@ -309,13 +310,17 @@ class VotanteForm(ModelForm): def save(self, commit=False): votante = super(VotanteForm, self).save(commit) + # Cria user u = User.objects.create( username=self.cleaned_data['username'], email=self.cleaned_data['email']) - u.set_password(self.cleaned_data['senha']) u.save() + # Adiciona user ao grupo + g = Group.objects.filter(name='Votante')[0] + u.groups.add(g) + votante.user = u votante.save() return votante