def comments_for_node(node_id): """Shows the comments attached to the given node.""" api = system_util.pillar_api() node = Node.find(node_id, api=api) project = Project({'_id': node.project}) can_post_comments = project.node_type_has_method('comment', 'POST', api=api) can_comment_override = request.args.get('can_comment', 'True') == 'True' can_post_comments = can_post_comments and can_comment_override # Query for all children, i.e. comments on the node. comments = Node.all( { 'where': { 'node_type': 'comment', 'parent': node_id }, }, api=api) def enrich(some_comment): some_comment['_user'] = subquery.get_user_info(some_comment['user']) some_comment['_is_own'] = some_comment['user'] == current_user.objectid some_comment['_current_user_rating'] = None # tri-state boolean some_comment[ '_rating'] = some_comment.properties.rating_positive - some_comment.properties.rating_negative if current_user.is_authenticated: for rating in some_comment.properties.ratings or (): if rating.user != current_user.objectid: continue some_comment['_current_user_rating'] = rating.is_positive for comment in comments['_items']: # Query for all grandchildren, i.e. replies to comments on the node. comment['_replies'] = Node.all( { 'where': { 'node_type': 'comment', 'parent': comment['_id'] }, }, api=api) enrich(comment) for reply in comment['_replies']['_items']: enrich(reply) nr_of_comments = sum(1 + comment['_replies']['_meta']['total'] for comment in comments['_items']) return render_template('nodes/custom/comment/list_embed.html', node_id=node_id, comments=comments, nr_of_comments=nr_of_comments, show_comments=True, can_post_comments=can_post_comments)
def comments_for_node(node_id): """Shows the comments attached to the given node. The URL can be overridden in order to define can_post_comments in a different way """ api = system_util.pillar_api() node = Node.find(node_id, api=api) project = Project({'_id': node.project}) can_post_comments = project.node_type_has_method('comment', 'POST', api=api) can_comment_override = request.args.get('can_comment', 'True') == 'True' can_post_comments = can_post_comments and can_comment_override return render_comments_for_node(node_id, can_post_comments=can_post_comments)
def commentform_for_node(node_id): """Shows only the comment for for comments attached to the given node. i.e. does not show the comments themselves, just the form to post a new comment. """ api = system_util.pillar_api() node = Node.find(node_id, api=api) project = Project({'_id': node.project}) can_post_comments = project.node_type_has_method('comment', 'POST', api=api) return render_template('nodes/custom/comment/list_embed.html', node_id=node_id, show_comments=False, can_post_comments=can_post_comments)