Пример #1
0
def post(post_id):
    """Post detail page."""

    form = CommentForm()

    if form.validate_on_submit():
        # If valid form is submitted, add comment and redirect back to page
        new_comment = Comment()
        new_comment.name = form.name.data
        new_comment.text = form.text.data
        new_comment.post_id = post_id
        new_comment.date = datetime.datetime.now()

        db.session.add(new_comment)
        db.session.commit()
        return redirect(request.url)

    else:
        # No form submitted or form is invalid, show post (with errors if appropriate)
        post = Post.query.get_or_404(post_id)
        tags = post.tags
        comments = post.comments.order_by(Comment.date.desc()).all()
        recent, top_tags = sidebar_data()

        return render_template(
            'post.html',
            post=post,
            tags=tags,
            comments=comments,
            recent=recent,
            top_tags=top_tags,
            form=form,
        )
Пример #2
0
def post(post_id):
    """Post detail page."""

    form = CommentForm()

    if form.validate_on_submit():
        # If valid form is submitted, add comment and redirect back to page
        new_comment = Comment()
        new_comment.name = form.name.data
        new_comment.text = form.text.data
        new_comment.post_id = post_id
        new_comment.date = datetime.datetime.now()

        db.session.add(new_comment)
        db.session.commit()
        return redirect(request.url)

    else:
        # No form submitted or form is invalid, show post (with errors if appropriate)
        post = Post.query.get_or_404(post_id)
        tags = post.tags
        comments = post.comments.order_by(Comment.date.desc()).all()
        recent, top_tags = sidebar_data()

        return render_template(
            'post.html',
            post=post,
            tags=tags,
            comments=comments,
            recent=recent,
            top_tags=top_tags,
            form=form,
        )