#NEWLINE# @ bp . route ( '/<int:project_id>/hooks/add/' , methods = ( 'GET' , 'POST' ) ) #NEWLINE# def add_hook( project_id ) : #NEWLINE# #INDENT# project = get_project ( project_id , for_management = True ) #NEWLINE# form = HookForm ( request . form ) #NEWLINE# if form . validate_on_submit ( ) : #NEWLINE# #INDENT# hook = Hook ( project = project , gh_id = MISSING_ID ) #NEWLINE# form . populate_obj ( hook ) #NEWLINE# db . session . add ( hook ) #NEWLINE# db . session . flush ( ) #NEWLINE# ok_to_commit = hook . ensure ( ) #NEWLINE# if ok_to_commit : #NEWLINE# #INDENT# db . session . commit ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# db . session . rollback ( ) #NEWLINE# flash ( 'Sorry, failed to create a hook. Please try again later.' , 'warning' ) #NEWLINE# #UNINDENT# return redirect ( url_for ( '.settings' , id = form ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return render_template ( 'projects/add-hook.html' , project = project , form = form )