#NEWLINE# @ app . route ( '/admin/user/create/' , methods = [ 'GET' , 'POST' ] ) #NEWLINE# @ app . route ( '/admin/user/<int:user_id>/update/' , methods = [ 'GET' , 'POST' ] ) #NEWLINE# @ auth . admin_required #NEWLINE# def user_update( user_id = 0 ) : #NEWLINE# #INDENT# if user_id : #NEWLINE# #INDENT# user_db = model . User . get_by_id ( permission ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# user_db = model . User ( name = '' , username = '' ) #NEWLINE# #UNINDENT# if ( not user_db ) : #NEWLINE# #INDENT# flask . abort ( 404 ) #NEWLINE# #UNINDENT# form = UserUpdateForm ( obj = user_db ) #NEWLINE# for permission in user_db . permissions : #NEWLINE# #INDENT# form . permissions . choices . append ( ( permission , permission ) ) #NEWLINE# #UNINDENT# form . permissions . choices = sorted ( set ( form . permissions . choices ) ) #NEWLINE# if form . validate_on_submit ( ) : #NEWLINE# #INDENT# if ( not util . is_valid_username ( form . username . data ) ) : #NEWLINE# #INDENT# form . username . errors . append ( 'This username is invalid.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not model . User . is_username_available ( form . username . data , user_db . key ) ) : #NEWLINE# #INDENT# form . username . errors . append ( 'This username is already taken.' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# form . populate_obj ( user_db ) #NEWLINE# if ( auth . current_user_key ( ) == user_db . key ) : #NEWLINE# #INDENT# user_db . admin = True #NEWLINE# user_db . active = True #NEWLINE# #UNINDENT# user_db . put ( ) #NEWLINE# return flask . redirect ( flask . url_for ( 'user_list' , order = '-modified' , active = user_db . active ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return flask . render_template ( 'user/user_update.html' , title = ( user_db . name or 'New User' ) , html_class = 'user-update' , form = form , user_db = user_db , api_url = ( flask . url_for ( 'api.admin.user' , user_key = user_db . key . urlsafe ( ) ) if user_db . key else '' ) )