#NEWLINE# @ mod . route ( '/subreddits/submit/' , methods = [ 'GET' , 'POST' ] ) #NEWLINE# def submit( ) : #NEWLINE# #INDENT# '\n    ' #NEWLINE# if ( g . user is None ) : #NEWLINE# #INDENT# flash ( 'You must be logged in to submit subreddits!' , 'danger' ) #NEWLINE# return redirect ( url_for ( 'frontends.login' , next = request . path ) ) #NEWLINE# #UNINDENT# form = SubmitForm ( request . form ) #NEWLINE# user_id = g . user . id #NEWLINE# if form . validate_on_submit ( ) : #NEWLINE# #INDENT# name = form . name . data . strip ( ) #NEWLINE# desc = form . desc . data . strip ( ) #NEWLINE# subreddit = Subreddit . query . filter_by ( name = name ) . first ( ) #NEWLINE# if name : #NEWLINE# #INDENT# flash ( 'subreddit already exists!' , 'danger' ) #NEWLINE# return render_template ( 'subreddits/submit.html' , form = form , user = g . user , subreddits = get_subreddits ( ) ) #NEWLINE# #UNINDENT# new_subreddit = Subreddit ( name = name , desc = desc , admin_id = user_id ) #NEWLINE# if ( not meets_subreddit_criterea ( subreddit ) ) : #NEWLINE# #INDENT# return render_template ( 'subreddits/submit.html' , form = form , user = g . user , subreddits = get_subreddits ( ) ) #NEWLINE# #UNINDENT# db . session . add ( new_subreddit ) #NEWLINE# db . session . commit ( ) #NEWLINE# flash ( 'Thanks for starting a community! Begin adding posts to your community                by clicking the red button to the right.' , 'success' ) #NEWLINE# return redirect ( url_for ( 'subreddits.permalink' , subreddit_name = new_subreddit . name ) ) #NEWLINE# #UNINDENT# return render_template ( 'subreddits/submit.html' , form = form , user = g . user , subreddits = get_subreddits ( ) )