|
@ -40,6 +40,9 @@ STATUS_USER_CHOICE = [ |
|
|
('X', _('Excluir Usuário')), |
|
|
('X', _('Excluir Usuário')), |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
def get_roles(): |
|
|
|
|
|
return [(g.id, g.name) for g in Group.objects.all().order_by('name')] |
|
|
|
|
|
|
|
|
class UsuarioCreateForm(ModelForm): |
|
|
class UsuarioCreateForm(ModelForm): |
|
|
|
|
|
|
|
|
username = forms.CharField(required=True, label="Nome de usuário") |
|
|
username = forms.CharField(required=True, label="Nome de usuário") |
|
@ -49,14 +52,15 @@ class UsuarioCreateForm(ModelForm): |
|
|
password2 = forms.CharField(required=True, widget=forms.PasswordInput, label='Confirmar senha') |
|
|
password2 = forms.CharField(required=True, widget=forms.PasswordInput, label='Confirmar senha') |
|
|
user_active = forms.ChoiceField(required=False, choices=YES_NO_CHOICES, label="Usuário ativo?", initial='True') |
|
|
user_active = forms.ChoiceField(required=False, choices=YES_NO_CHOICES, label="Usuário ativo?", initial='True') |
|
|
|
|
|
|
|
|
ROLES = [(g.id, g.name) for g in Group.objects.all().order_by('name')] |
|
|
#ROLES = [(g.id, g.name) for g in Group.objects.all().order_by('name')] |
|
|
|
|
|
|
|
|
roles = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple(), choices=ROLES) |
|
|
roles = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple(), choices=get_roles) |
|
|
|
|
|
|
|
|
class Meta: |
|
|
class Meta: |
|
|
model = get_user_model() |
|
|
model = get_user_model() |
|
|
fields = ['username', 'firstname', 'lastname', 'email', 'password1', 'password2', 'user_active', 'roles'] |
|
|
fields = ['username', 'firstname', 'lastname', 'email', 'password1', 'password2', 'user_active', 'roles'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def clean(self): |
|
|
def clean(self): |
|
|
super(UsuarioCreateForm, self).clean() |
|
|
super(UsuarioCreateForm, self).clean() |
|
|
|
|
|
|
|
@ -94,12 +98,14 @@ class UsuarioCreateForm(ModelForm): |
|
|
row4) |
|
|
row4) |
|
|
|
|
|
|
|
|
class UsuarioEditForm(ModelForm): |
|
|
class UsuarioEditForm(ModelForm): |
|
|
ROLES = [(g.id, g.name) for g in Group.objects.all().order_by('name')] |
|
|
# ROLES = [(g.id, g.name) for g in Group.objects.all().order_by('name')] |
|
|
|
|
|
|
|
|
|
|
|
ROLES = [] |
|
|
|
|
|
|
|
|
password1 = forms.CharField(required=False, widget=forms.PasswordInput, label='Senha') |
|
|
password1 = forms.CharField(required=False, widget=forms.PasswordInput, label='Senha') |
|
|
password2 = forms.CharField(required=False, widget=forms.PasswordInput, label='Confirmar senha') |
|
|
password2 = forms.CharField(required=False, widget=forms.PasswordInput, label='Confirmar senha') |
|
|
user_active = forms.ChoiceField(choices=YES_NO_CHOICES, required=True, label="Usuário ativo?", initial='True') |
|
|
user_active = forms.ChoiceField(choices=YES_NO_CHOICES, required=True, label="Usuário ativo?", initial='True') |
|
|
roles = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple(), choices=ROLES) |
|
|
roles = forms.MultipleChoiceField(required=True, widget=forms.CheckboxSelectMultiple(), choices=get_roles) |
|
|
|
|
|
|
|
|
class Meta: |
|
|
class Meta: |
|
|
model = get_user_model() |
|
|
model = get_user_model() |
|
@ -115,6 +121,7 @@ class UsuarioEditForm(ModelForm): |
|
|
[('password1', 6), |
|
|
[('password1', 6), |
|
|
('password2', 6)]) |
|
|
('password2', 6)]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
row3 = to_row([(form_actions(label='Salvar Alterações'), 6)]) |
|
|
row3 = to_row([(form_actions(label='Salvar Alterações'), 6)]) |
|
|
|
|
|
|
|
|
self.helper = FormHelper() |
|
|
self.helper = FormHelper() |
|
|