Browse Source

Adiciona grupo ao usuario parlamentar

pull/906/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
81c9ac90a6
  1. 7
      sapl/parlamentares/forms.py

7
sapl/parlamentares/forms.py

@ -1,4 +1,5 @@
from datetime import date, timedelta from datetime import date, timedelta
from django.contrib.auth.models import Group
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import Fieldset, Layout from crispy_forms.layout import Fieldset, Layout
@ -309,13 +310,17 @@ class VotanteForm(ModelForm):
def save(self, commit=False): def save(self, commit=False):
votante = super(VotanteForm, self).save(commit) votante = super(VotanteForm, self).save(commit)
# Cria user
u = User.objects.create( u = User.objects.create(
username=self.cleaned_data['username'], username=self.cleaned_data['username'],
email=self.cleaned_data['email']) email=self.cleaned_data['email'])
u.set_password(self.cleaned_data['senha']) u.set_password(self.cleaned_data['senha'])
u.save() u.save()
# Adiciona user ao grupo
g = Group.objects.filter(name='Votante')[0]
u.groups.add(g)
votante.user = u votante.user = u
votante.save() votante.save()
return votante return votante

Loading…
Cancel
Save