@ -177,54 +177,72 @@ 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 = [ ]
ROLES = [ ]
first_name = forms . CharField (
required = False ,
label = " Nome " ,
max_length = 30 )
last_name = forms . CharField (
required = False ,
label = " Sobrenome " ,
max_length = 30 )
password1 = forms . CharField (
password1 = forms . CharField (
required = False , widget = forms . PasswordInput , label = ' Senha ' )
required = False ,
widget = forms . PasswordInput ,
label = ' Senha ' )
password2 = forms . CharField (
password2 = forms . CharField (
required = False , widget = forms . PasswordInput , label = ' Confirmar senha ' )
required = False , widget = forms . PasswordInput ,
user_active = forms . ChoiceField ( choices = YES_NO_CHOICES , required = True ,
label = ' Confirmar senha ' )
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 (
roles = forms . MultipleChoiceField (
required = True , widget = forms . CheckboxSelectMultiple ( ) , choices = get_roles )
required = True ,
widget = forms . CheckboxSelectMultiple ( ) ,
choices = get_roles )
class Meta :
class Meta :
model = get_user_model ( )
model = get_user_model ( )
fields = [
fields = [
get_user_model ( ) . USERNAME_FIELD , ' password1 ' ,
get_user_model ( ) . USERNAME_FIELD ,
' password2 ' , ' user_active ' , ' roles '
" first_name " ,
] + ( [ ' email ' ]
" last_name " ,
if get_user_model ( ) . USERNAME_FIELD != ' email ' else [ ] )
' password1 ' ,
' password2 ' ,
' user_active ' ,
' roles ' ]
def __init__ ( self , * args , * * kwargs ) :
if get_user_model ( ) . USERNAME_FIELD != ' email ' :
fields . extend ( [ ' email ' ] )
def __init__ ( self , * args , * * kwargs ) :
super ( UsuarioEditForm , self ) . __init__ ( * args , * * kwargs )
super ( UsuarioEditForm , self ) . __init__ ( * args , * * kwargs )
row1 = to_row ( [ ( ' username ' , 12 ) ] )
rows = to_row ( (
row2 = to_row ( [ ( ' email ' , 6 ) ,
( ' username ' , 12 ) ,
( ' user_activ e' , 6 ) ] )
( ' first_nam e' , 6 ) ,
row3 = to_row (
( ' last_name ' , 6 ) ,
[ ( ' password1 ' , 6 ) ,
( ' email ' , 6 ) ,
( ' password2 ' , 6 ) ] )
( ' user_active ' , 6 ) ,
( ' password1 ' , 6 ) ,
row4 = to_row ( [ ( form_actions ( label = ' Salvar Alterações ' ) , 6 ) ] )
( ' password2 ' , 6 ) ) )
self . helper = SaplFormHelper ( )
self . helper = SaplFormHelper ( )
self . helper . layout = Layout (
self . helper . layout = Layout (
row1 ,
rows ,
row2 ,
row3 ,
' roles ' ,
' roles ' ,
form_actions ( label = ' Salvar Alterações ' ) )
form_actions ( label = ' Salvar Alterações ' ) )
def clean ( self ) :
def clean ( self ) :
super ( UsuarioEditForm , self ) . clean ( )
super ( ) . clean ( )
if not self . is_valid ( ) :
if not self . is_valid ( ) :
return self . cleaned_data
return self . cleaned_data
data = self . cleaned_data
data = self . cleaned_data
if data [ ' password1 ' ] and data [ ' password1 ' ] != data [ ' password2 ' ] :
if data [ ' password1 ' ] and data [ ' password1 ' ] != data [ ' password2 ' ] :
self . logger . error ( ' Erro de validação. Senhas informadas ( {} , {} ) são diferentes. ' . format (
self . logger . error ( " Erro de validação. Senhas informadas ( {} , {} ) são diferentes. "
data [ ' password1 ' ] , data [ ' password2 ' ] ) )
. format ( data [ ' password1 ' ] , data [ ' password2 ' ] ) )
raise ValidationError ( ' Senhas informadas são diferentes ' )
raise ValidationError ( ' Senhas informadas são diferentes ' )
return data
return data