def new_topic(forum_id, slug=None): forum = Forum.query.filter_by(id=forum_id).first_or_404() if forum.locked: flash("This forum is locked; you cannot submit new topics or posts.", "danger") return redirect(forum.url) if not can_post_topic(user=current_user, forum=forum): flash("You do not have the permissions to create a new topic.", "danger") return redirect(forum.url) form = NewTopicForm() if form.validate_on_submit(): if request.form['button'] == 'preview': return render_template("forum/new_topic.html", forum=forum, form=form, preview=form.content.data) else: topic = form.save(current_user, forum) # redirect to the new topic return redirect(url_for('forum.view_topic', topic_id=topic.id)) return render_template("forum/new_topic.html", forum=forum, form=form)
def new_topic(forum_id, slug=None): forum = Forum.query.filter_by(id=forum_id).first_or_404() if not can_post_topic(user=current_user, forum=forum): flash("You do not have the permissions to create a new topic.", "danger") return redirect(forum.url) form = NewTopicForm() if form.validate_on_submit(): if request.form['button'] == 'preview': return render_template("forum/new_topic.html", forum=forum, form=form, preview=form.content.data) else: topic = form.save(current_user, forum) # redirect to the new topic return redirect(url_for('forum.view_topic', topic_id=topic.id)) return render_template("forum/new_topic.html", forum=forum, form=form)
def new_topic(forum_id, slug=None): forum = Forum.query.filter_by(id=forum_id).first_or_404() if forum.locked: flash("This forum is locked; you cannot submit new topics or posts.", "danger") return redirect(forum.url) if not can_post_topic(user=current_user, forum=forum): flash("You do not have the permissions to create a new topic.", "danger") return redirect(forum.url) form = NewTopicForm() if form.validate_on_submit(): topic = form.save(current_user, forum) # redirect to the new topic return redirect(url_for('forum.view_topic', topic_id=topic.id)) return render_template("forum/new_topic.html", forum=forum, form=form)
def new_topic(forum_id, slug=None): forum_instance = Forum.query.filter_by(id=forum_id).first_or_404() if not can_post_topic(user=current_user, forum=forum): flash(_("You do not have the permissions to create a new topic."), "danger") return redirect(forum.url) form = NewTopicForm() if request.method == "POST": if "preview" in request.form and form.validate(): return render_template( "forum/new_topic.html", forum=forum_instance, form=form, preview=form.content.data ) if "submit" in request.form and form.validate(): topic = form.save(current_user, forum_instance) # redirect to the new topic return redirect(url_for('forum.view_topic', topic_id=topic.id)) return render_template( "forum/new_topic.html", forum=forum_instance, form=form )
def new_topic(forum_id, slug=None): forum_instance = Forum.query.filter_by(id=forum_id).first_or_404() if not can_post_topic(user=current_user, forum=forum): flash(_("You do not have the permissions to create a new topic."), "danger") return redirect(forum.url) form = NewTopicForm() if request.method == "POST": if "preview" in request.form and form.validate(): return render_template("forum/new_topic.html", forum=forum_instance, form=form, preview=form.content.data) if "submit" in request.form and form.validate(): topic = form.save(current_user, forum_instance) # redirect to the new topic return redirect(url_for('forum.view_topic', topic_id=topic.id)) return render_template("forum/new_topic.html", forum=forum_instance, form=form)