def submit(subreddit_name=None): """ """ if g.user is None: flash('You must be logged in to submit posts!', 'danger') return redirect(url_for('frontends.login', next=request.path)) user_id = g.user.id subreddit = Subreddit.query.filter_by(name=subreddit_name).first() if not subreddit: abort(404) form = SubmitForm(request.form) if form.validate_on_submit(): title = form.title.data.strip() link = form.link.data.strip() text = form.text.data.strip() thread = Thread(title=title, link=link, text=text, user_id=user_id, subreddit_id=subreddit.id) if not meets_thread_criterea(thread): return render_template('threads/submit.html', form=form, user=g.user, cur_subreddit=subreddit.name) db.session.add(thread) db.session.commit() thread.set_hotness() flash('thanks for submitting!', 'success') return redirect(url_for('subreddits.permalink', subreddit_name=subreddit.name)) return render_template('threads/submit.html', form=form, user=g.user, cur_subreddit=subreddit, subreddits=get_subreddits())
def submit(): """ """ if g.user is None: flash('You must be logged in to submit subreddits!', 'danger') return redirect(url_for('frontends.login', next=request.path)) form = SubmitForm(request.form) user_id = g.user.id if form.validate_on_submit(): name = form.name.data.strip() desc = form.desc.data.strip() subreddit = Subreddit.query.filter_by(name=name).first() if subreddit: flash('subreddit already exists!', 'danger') return render_template('subreddits/submit.html', form=form, user=g.user, subreddits=get_subreddits()) new_subreddit = Subreddit(name=name, desc=desc, admin_id=user_id) if not meets_subreddit_criterea(subreddit): return render_template('subreddits/submit.html', form=form, user=g.user, subreddits=get_subreddits()) db.session.add(new_subreddit) db.session.commit() flash('Thanks for starting a community! Begin adding posts to your community\ by clicking the red button to the right.', 'success') return redirect(url_for('subreddits.permalink', subreddit_name=new_subreddit.name)) return render_template('subreddits/submit.html', form=form, user=g.user, subreddits=get_subreddits())
def submit(subreddit_name=None): """ """ if g.user is None: flash('You must be logged in to submit posts!', 'danger') return redirect(url_for('frontends.login', next=request.path)) user_id = g.user.id subreddit = Subreddit.query.filter_by(name=subreddit_name).first() if not subreddit: abort(404) form = SubmitForm(request.form) if form.validate_on_submit(): title = form.title.data.strip() link = form.link.data.strip() text = form.text.data.strip() thread = Thread(title=title, link=link, text=text, user_id=user_id, subreddit_id=subreddit.id) if not meets_thread_criterea(thread): return render_template('threads/submit.html', form=form, user=g.user, cur_subreddit=subreddit.name) db.session.add(thread) db.session.commit() thread.set_hotness() flash('thanks for submitting!', 'success') return redirect( url_for('subreddits.permalink', subreddit_name=subreddit.name)) return render_template('threads/submit.html', form=form, user=g.user, cur_subreddit=subreddit, subreddits=get_subreddits())