#NEWLINE# def user_set_password( request , user_id = None , user_id_list = None ) : #NEWLINE# #INDENT# Permission . check_permissions ( request . user , ( permission_user_edit , ) ) #NEWLINE# post_action_redirect = None #NEWLINE# if user_id : #NEWLINE# #INDENT# users = get_user_model ( ) . objects . filter ( pk = user_id ) #NEWLINE# post_action_redirect = reverse ( 'user_management:user_list' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if user_id_list : #NEWLINE# #INDENT# users = get_user_model ( ) . objects . filter ( pk__in = user_id_list ) #NEWLINE# #UNINDENT# #UNINDENT# if ( not users ) : #NEWLINE# #INDENT# messages . error ( request , _ ( 'Must provide at least one user.' ) ) #NEWLINE# return HttpResponseRedirect ( request . META . get ( 'HTTP_REFERER' , reverse ( settings . LOGIN_REDIRECT_URL ) ) ) #NEWLINE# #UNINDENT# next = request . POST . get ( 'next' , request . GET . get ( 'next' , ( post_action_redirect if post_action_redirect else request . META . get ( 'HTTP_REFERER' , reverse ( settings . LOGIN_REDIRECT_URL ) ) ) ) ) #NEWLINE# if ( request . method == 'POST' ) : #NEWLINE# #INDENT# form = PasswordForm ( request . POST ) #NEWLINE# if form . is_valid ( ) : #NEWLINE# #INDENT# password_1 = form . cleaned_data [ 'new_password_1' ] #NEWLINE# password_2 = form . cleaned_data [ 'new_password_2' ] #NEWLINE# if ( password_1 != password_2 ) : #NEWLINE# #INDENT# messages . error ( request , _ ( 'Passwords do not match, try again.' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# for user in users : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# if ( user . is_superuser or user . is_staff ) : #NEWLINE# #INDENT# messages . error ( request , _ ( 'Super user and staff user password reseting is not allowed, use the admin interface for these cases.' ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# user . set_password ( password_1 ) #NEWLINE# user . save ( ) #NEWLINE# messages . success ( request , ( _ ( 'Successfull password reset for user: %s.' ) % user ) ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as exception : #NEWLINE# #INDENT# messages . error ( request , ( _ ( 'Error reseting password for user "%(user)s": %(error)s' ) % { #NEWLINE# #INDENT# 'user' : user , #NEWLINE# 'error' : exception , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# #UNINDENT# return HttpResponseRedirect ( next ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# form = PasswordForm ( ) #NEWLINE# #UNINDENT# context = { #NEWLINE# #INDENT# 'next' : next , #NEWLINE# 'form' : user_id_list , #NEWLINE# #UNINDENT# } #NEWLINE# if ( users . count ( ) == 1 ) : #NEWLINE# #INDENT# context [ 'object' ] = users . first ( ) #NEWLINE# context [ 'title' ] = ( _ ( 'Reseting password for user: %s' ) % ', ' . join ( [ unicode ( d ) for d in users ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( users ) > 1 ) : #NEWLINE# #INDENT# context [ 'title' ] = ( _ ( 'Reseting password for users: %s' ) % ', ' . join ( [ unicode ( d ) for d in users ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# return render_to_response ( 'appearance/generic_form.html' , context , context_instance = RequestContext ( request ) )