@@ -0,0 +1,2275 @@
+from flask import jsonify, request, g, url_for, current_app%0Afrom .. import db%0Afrom ..models import Post, Permission, Comment%0Afrom . import api%0Afrom .decorators import permission_required%0A%0A%0A@api.route('/comments/')%0Adef get_comments():%0A    page = request.args.get('page', 1, type=int)%0A    pagination = Comment.query.order_by(Comment.timestamp.desc()).paginate(%0A        page, per_page=current_app.config%5B'FLASKY_COMMENTS_PER_PAGE'%5D,%0A        error_out=False)%0A    comments = pagination.items%0A    prev = None%0A    if pagination.has_prev:%0A        prev = url_for('api.get_comments', page=page-1, _external=True)%0A    next = None%0A    if pagination.has_next:%0A        next = url_for('api.get_comments', page=page+1, _external=True)%0A    return jsonify(%7B%0A        'comments': %5Bcomment.to_json() for comment in comments%5D,%0A        'prev': prev,%0A        'next': next,%0A        'count': pagination.total%0A    %7D)%0A%0A%0A@api.route('/comments/%3Cint:id%3E')%0Adef get_comment(id):%0A    comment = Comment.query.get_or_404(id)%0A    return jsonify(comment.to_json())%0A%0A%0A@api.route('/posts/%3Cint:id%3E/comments/')%0Adef get_post_comments(id):%0A    post = Post.query.get_or_404(id)%0A    page = request.args.get('page', 1, type=int)%0A    pagination = post.comments.order_by(Comment.timestamp.asc()).paginate(%0A        page, per_page=current_app.config%5B'FLASKY_COMMENTS_PER_PAGE'%5D,%0A        error_out=False)%0A    comments = pagination.items%0A    prev = None%0A    if pagination.has_prev:%0A        prev = url_for('api.get_post_comments', page=page-1, _external=True)%0A    next = None%0A    if pagination.has_next:%0A        next = url_for('api.get_post_comments', page=page+1, _external=True)%0A    return jsonify(%7B%0A        'comments': %5Bcomment.to_json() for comment in comments%5D,%0A        'prev': prev,%0A        'next': next,%0A        'count': pagination.total%0A    %7D)%0A%0A%0A@api.route('/posts/%3Cint:id%3E/comments/', methods=%5B'POST'%5D)%0A@permission_required(Permission.COMMENT)%0Adef new_post_comment(id):%0A    post = Post.query.get_or_404(id)%0A    comment = Comment.from_json(request.json)%0A    comment.author = g.current_user%0A    comment.post = post%0A    db.session.add(comment)%0A    db.session.commit()%0A    return jsonify(comment.to_json()), 201, %5C%0A        %7B'Location': url_for('api.get_comment', id=comment.id,%0A                             _external=True)%7D%0A

Create comments.py