Beispiel #1
0
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)
Beispiel #2
0
def new_topic(forum_id):
    forum = Forum.query.filter_by(id=forum_id).first()

    if not perm_post_topic(user=current_user, forum=forum):
        flash("You do not have the permissions to create a new topic.", "error")
        return redirect(url_for('forum.view_forum', forum_id=forum.id))

    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)
Beispiel #3
0
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)
Beispiel #4
0
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)
Beispiel #5
0
def edit_post(post_id):
    post = Post.query.filter_by(id=post_id).first_or_404()

    if not Permission(CanEditPost):
        flash(_("You do not have the permissions to edit this post."),
              "danger")
        return redirect(post.topic.url)

    if post.first_post:
        form = NewTopicForm()
    else:
        form = ReplyForm()

    if form.validate_on_submit():
        if "preview" in request.form:
            return render_template(
                "forum/new_post.html", topic=post.topic,
                form=form, preview=form.content.data, edit_mode=True
            )
        else:
            form.populate_obj(post)
            post.date_modified = time_utcnow()
            post.modified_by = current_user.username
            post.save()

            if post.first_post:
                post.topic.title = form.title.data
                post.topic.save()
            return redirect(post.topic.url)
    else:
        if post.first_post:
            form.title.data = post.topic.title

        form.content.data = post.content

    return render_template(
        "forum/new_post.html",
        topic=post.topic,
        form=form,
        edit_mode=True
    )
Beispiel #6
0
def new_topic(forum_id, slug=None):
    forum_instance = Forum.query.filter_by(id=forum_id).first_or_404()

    if not Permission(CanPostTopic):
        flash(_("You do not have the permissions to create a new topic."),
              "danger")
        return redirect(forum_instance.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)
Beispiel #7
0
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
    )
Beispiel #8
0
def edit_post(post_id):
    post = Post.query.filter_by(id=post_id).first_or_404()

    if not Permission(CanEditPost):
        flash(_("You do not have the permissions to edit this post."),
              "danger")
        return redirect(post.topic.url)

    if post.first_post:
        form = NewTopicForm()
    else:
        form = ReplyForm()

    if form.validate_on_submit():
        if "preview" in request.form:
            return render_template("forum/new_post.html",
                                   topic=post.topic,
                                   form=form,
                                   preview=form.content.data,
                                   edit_mode=True)
        else:
            form.populate_obj(post)
            post.date_modified = time_utcnow()
            post.modified_by = current_user.username
            post.save()

            if post.first_post:
                post.topic.title = form.title.data
                post.topic.save()
            return redirect(post.topic.url)
    else:
        if post.first_post:
            form.title.data = post.topic.title

        form.content.data = post.content

    return render_template("forum/new_post.html",
                           topic=post.topic,
                           form=form,
                           edit_mode=True)
Beispiel #9
0
 def form(self):
     current_app.pluggy.hook.flaskbb_form_topic(form=NewTopicForm)
     return NewTopicForm()