Beispiel #1
0
def view_topic(topic_id):
    page = request.args.get('page', 1, type=int)

    topic = Topic.query.filter_by(id=topic_id).first()
    posts = Post.query.filter_by(topic_id=topic.id).\
        paginate(page, current_app.config['POSTS_PER_PAGE'], False)

    # Count the topic views
    topic.views += 1

    # Update the topicsread status if he hasn't read it
    topic.update_read(current_user)
    topic.save()

    form = None

    if not topic.locked \
        and not topic.forum.locked \
        and perm_post_reply(user=current_user,
                            forum=topic.forum):

            form = QuickreplyForm()
            if form.validate_on_submit():
                post = form.save(current_user, topic)
                return view_post(post.id)

    return render_template("forum/topic.html", topic=topic, posts=posts,
                           per_page=current_app.config['POSTS_PER_PAGE'],
                           last_seen=time_diff(), form=form)
Beispiel #2
0
def new_post(topic_id):
    topic = Topic.query.filter_by(id=topic_id).first()

    if topic.locked:
        flash("The topic is locked.", "error")
        return redirect(url_for("forum.view_forum", forum_id=topic.forum_id))

    if not perm_post_reply(user=current_user, forum=topic.forum):
        flash("You do not have the permissions to delete the topic", "error")
        return redirect(url_for("forum.view_forum", forum_id=topic.forum_id))

    form = ReplyForm()
    if form.validate_on_submit():
        post = form.save(current_user, topic)
        return view_post(post.id)

    return render_template("forum/new_post.html", topic=topic, form=form)