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