<s> """<STR_LIT:U+0020>""" <EOL> from flask import ( Blueprint , request , render_template , flash , g , session , <EOL> redirect , url_for , abort ) <EOL> from flask_reddit . threads . forms import SubmitForm <EOL> from flask_reddit . threads . models import Thread <EOL> from flask_reddit . users . models import User <EOL> from flask_reddit . subreddits . models import Subreddit <EOL> from flask_reddit . frontends . views import get_subreddits <EOL> from flask_reddit import db <EOL> mod = Blueprint ( '<STR_LIT>' , __name__ , url_prefix = '<STR_LIT>' ) <EOL> @ mod . before_request <EOL> def before_request ( ) : <EOL> g . user = None <EOL> if '<STR_LIT>' in session : <EOL> g . user = User . query . get ( session [ '<STR_LIT>' ] ) <EOL> def meets_thread_criterea ( thread ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if not thread . title : <EOL> flash ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return False <EOL> if not thread . text and not thread . link : <EOL> flash ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return False <EOL> dup_link = Thread . query . filter_by ( link = thread . link ) . first ( ) <EOL> if not thread . text and dup_link : <EOL> flash ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return False <EOL> return True <EOL> @ mod . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def submit ( subreddit_name = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> if g . user is None : <EOL> flash ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' , next = request . path ) ) <EOL> user_id = g . user . id <EOL> subreddit = Subreddit . query . filter_by ( name = subreddit_name ) . first ( ) <EOL> if not subreddit : <EOL> abort ( <NUM_LIT> ) <EOL> form = SubmitForm ( request . form ) <EOL> if form . validate_on_submit ( ) : <EOL> title = form . title . data . strip ( ) <EOL> link = form . link . data . strip ( ) <EOL> text = form . text . data . strip ( ) <EOL> thread = Thread ( title = title , link = link , text = text , <EOL> user_id = user_id , subreddit_id = subreddit . id ) <EOL> if not meets_thread_criterea ( thread ) : <EOL> return render_template ( '<STR_LIT>' , form = form , user = g . user , <EOL> cur_subreddit = subreddit . name ) <EOL> db . session . add ( thread ) <EOL> db . session . commit ( ) <EOL> thread . set_hotness ( ) <EOL> flash ( '<STR_LIT>' , '<STR_LIT:success>' ) <EOL> return redirect ( url_for ( '<STR_LIT>' , subreddit_name = subreddit . name ) ) <EOL> return render_template ( '<STR_LIT>' , form = form , user = g . user , <EOL> cur_subreddit = subreddit , subreddits = get_subreddits ( ) ) <EOL> @ mod . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def delete ( ) : <EOL> """<STR_LIT:U+0020>""" <EOL> pass <EOL> @ mod . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def edit ( ) : <EOL> """<STR_LIT:U+0020>""" <EOL> pass <EOL> @ mod . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def thread_permalink ( subreddit_name = None , thread_id = None , title = None ) : <EOL> """<STR_LIT:U+0020>""" <EOL> thread_id = thread_id or - <NUM_LIT> <EOL> thread = Thread . query . get_or_404 ( int ( thread_id ) ) <EOL> subreddit = Subreddit . query . filter_by ( name = subreddit_name ) . first ( ) <EOL> subreddits = get_subreddits ( ) <EOL> return render_template ( '<STR_LIT>' , user = g . user , thread = thread , <EOL> cur_subreddit = subreddit , subreddits = subreddits ) <EOL> @ mod . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def submit_comment ( ) : <EOL> """<STR_LIT:U+0020>""" <EOL> pass <EOL> @ mod . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def delete_comment ( ) : <EOL> """<STR_LIT:U+0020>""" <EOL> pass <EOL> @ mod . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def comment_permalink ( ) : <EOL> """<STR_LIT:U+0020>""" <EOL> pass </s>
