예제 #1
0
파일: blog.py 프로젝트: MaXianSeng/flask
def show_post(post_id):
    post = Post.query.get_or_404(post_id)
    page = request.args.get('page', 1, type=int)
    per_page = current_app.config['BLUELOG_COMMENT_PER_PAGE']
    pagination = Comment.query.with_parent(post).filter_by(reviewed=True).order_by(Comment.timestamp.asc()).paginate(page, per_page)
    comments = pagination.items

    form = CommentForm()
    from_admin = False
    reviewed = False #注意,如果为False则不会在页面中显示,因为32行规定只有为True才会显示,所以提交评论后应该在评论批准里批准为True

    if form.validate_on_submit():
        author = form.author.data
        email = form.email.data
        site = form.site.data
        body = form.body.data
        comment = Comment( 
            author=author, email=email, site=site, body=body,
            from_admin=from_admin, reviewed=reviewed, post=post)

        replied_comment_id = request.args.get('reply_to')
        if replied_comment_id:
            replied_comment = Comment.query.get_or_404(replied_comment_id)
            comment.replied = replied_comment

        db.session.add(comment)
        db.session.commit()
        send_comment_mail(post) #发邮件提醒评论
        flash('Comment success', 'info')

        return redirect(url_for('blog.show_post', post_id=post_id))

    return render_template('blog/post.html', post=post, pagination=pagination,
        comments=comments, form=form)
예제 #2
0
def edit_comment(comment_id):
    form = CommentForm()
    comment = Comment.query.get_or_404(comment_id)
    if form.validate_on_submit():
        comment.author = form.author.data
        comment.email = form.email.data
        comment.site = form.site.data
        comment.body = form.body.data
        db.session.commit()
        flash('Edit successed.', 'success')
        return redirect(url_for('.manage_comment'))
    form.author.data = comment.author
    form.email.data = comment.email
    form.site.data = comment.site
    form.body.data = comment.body
    return render_template('admin/edit_comment.html', form=form)