コード例 #1
0
ファイル: views.py プロジェクト: Doster-d/OnyxForum
    def get(self, topic_id, slug=None):
        page = request.args.get("page", 1, type=int)

        # Fetch some information about the topic
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))

        # Count the topic views
        topic.views += 1
        topic.save()

        # Update the topicsread status if the user hasn't read it
        forumsread = None
        if current_user.is_authenticated:
            forumsread = ForumsRead.query.filter_by(
                user_id=current_user.id, forum_id=topic.forum_id).first()

        topic.update_read(real(current_user), topic.forum, forumsread)

        # fetch the posts in the topic
        posts = Post.query.outerjoin(User, Post.user_id == User.id).filter(
            Post.topic_id == topic.id).add_entity(User).order_by(
                Post.id.asc()).paginate(page, flaskbb_config["POSTS_PER_PAGE"],
                                        False)

        # Abort if there are no posts on this page
        if len(posts.items) == 0:
            abort(404)

        return render_template("forum/topic.html",
                               topic=topic,
                               posts=posts,
                               last_seen=time_diff(),
                               form=self.form())
コード例 #2
0
    def post(self, topic_id, slug=None):
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))
        form = self.form()

        if not form:
            flash(_('Cannot post reply'), 'warning')
            return redirect('forum.view_topic', topic_id=topic_id, slug=slug)

        elif form.validate_on_submit():
            post = form.save(real(current_user), topic)
            return redirect(url_for('forum.view_post', post_id=post.id))

        else:
            for e in form.errors.get('content', []):
                flash(e, 'danger')
            return redirect(url_for('forum.view_topic', topic_id=topic_id, slug=slug))
コード例 #3
0
ファイル: views.py プロジェクト: flaskbb/flaskbb
    def post(self, topic_id, slug=None):
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))
        form = self.form()

        if not form:
            flash(_("Cannot post reply"), "warning")
            return redirect(topic.url)

        elif form.validate_on_submit():
            post = form.save(real(current_user), topic)
            return redirect(post.url)

        else:
            for e in form.errors.get("content", []):
                flash(e, "danger")
            return redirect(topic.url)
コード例 #4
0
ファイル: views.py プロジェクト: justanr/flaskbb
    def post(self, topic_id, slug=None):
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))
        form = self.form()

        if not form:
            flash(_("Cannot post reply"), "warning")
            return redirect("forum.view_topic", topic_id=topic_id, slug=slug)

        elif form.validate_on_submit():
            post = form.save(real(current_user), topic)
            return redirect(url_for("forum.view_post", post_id=post.id))

        else:
            for e in form.errors.get("content", []):
                flash(e, "danger")
            return redirect(
                url_for("forum.view_topic", topic_id=topic_id, slug=slug)
            )
コード例 #5
0
def view_topic(topic_id, slug=None):
    page = request.args.get('page', 1, type=int)

    # Fetch some information about the topic
    topic = Topic.get_topic(topic_id=topic_id, user=current_user)

    # Count the topic views
    topic.views += 1
    topic.save()

    # fetch the posts in the topic
    posts = Post.query.\
        join(User, Post.user_id == User.id).\
        filter(Post.topic_id == topic.id).\
        add_entity(User).\
        order_by(Post.id.asc()).\
        paginate(page, flaskbb_config['POSTS_PER_PAGE'], False)

    # Abort if there are no posts on this page
    if len(posts.items) == 0:
        abort(404)

    # Update the topicsread status if the user hasn't read it
    forumsread = None
    if current_user.is_authenticated:
        forumsread = ForumsRead.query.\
            filter_by(user_id=current_user.id,
                      forum_id=topic.forum.id).first()

    topic.update_read(current_user, topic.forum, forumsread)

    form = None
    if Permission(CanPostReply):
        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,
                           last_seen=time_diff(),
                           form=form)
コード例 #6
0
ファイル: views.py プロジェクト: justanr/flaskbb
    def get(self, topic_id, slug=None):
        page = request.args.get("page", 1, type=int)

        # Fetch some information about the topic
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))

        # Count the topic views
        topic.views += 1
        topic.save()

        # Update the topicsread status if the user hasn't read it
        forumsread = None
        if current_user.is_authenticated:
            forumsread = ForumsRead.query.filter_by(
                user_id=current_user.id,
                forum_id=topic.forum_id).first()

        topic.update_read(real(current_user), topic.forum, forumsread)

        # fetch the posts in the topic
        posts = Post.query.outerjoin(
            User, Post.user_id == User.id
        ).filter(
            Post.topic_id == topic.id
        ).add_entity(
            User
        ).order_by(
            Post.id.asc()
        ).paginate(page, flaskbb_config["POSTS_PER_PAGE"], False)

        # Abort if there are no posts on this page
        if len(posts.items) == 0:
            abort(404)

        return render_template(
            "forum/topic.html",
            topic=topic,
            posts=posts,
            last_seen=time_diff(),
            form=self.form()
        )
コード例 #7
0
ファイル: views.py プロジェクト: djsilcock/flaskbb
def view_topic(topic_id, slug=None):
    page = request.args.get('page', 1, type=int)

    # Fetch some information about the topic
    topic = Topic.get_topic(topic_id=topic_id, user=current_user)

    # Count the topic views
    topic.views += 1
    topic.save()

    # fetch the posts in the topic
    posts = Post.query.\
        outerjoin(User, Post.user_id == User.id).\
        filter(Post.topic_id == topic.id).\
        add_entity(User).\
        order_by(Post.id.asc()).\
        paginate(page, flaskbb_config['POSTS_PER_PAGE'], False)

    # Abort if there are no posts on this page
    if len(posts.items) == 0:
        abort(404)

    # Update the topicsread status if the user hasn't read it
    forumsread = None
    if current_user.is_authenticated:
        forumsread = ForumsRead.query.\
            filter_by(user_id=current_user.id,
                      forum_id=topic.forum.id).first()

    topic.update_read(current_user, topic.forum, forumsread)

    form = None
    if Permission(CanPostReply):
        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,
                           last_seen=time_diff(), form=form)
コード例 #8
0
ファイル: views.py プロジェクト: zhonli/flaskbb
    def post(self, topic_id, slug=None):
        topic = Topic.get_topic(topic_id=topic_id, user=real(current_user))
        form = self.form()

        if not form:
            flash(_("Cannot post reply"), "warning")
            return redirect("forum.view_topic", topic_id=topic_id, slug=slug)

        elif form.validate_on_submit():
            try:
                post = form.save(real(current_user), topic)
                return redirect(url_for("forum.view_post", post_id=post.id))
            except StopNewPost as e:
                flash(e.reason, "danger")
            except BaseFlaskBBError as e:
                flask(e.reason, "warning")
            except Exception:
                flash(_("Unrecoverable error while posting reply"))
        else:
            for e in form.errors.get("content", []):
                flash(e, "danger")

        return self.get(topic_id=topic_id, slug=slug)