def comments(context, reference_to=None, depth=0):
    blog_post = context.get('object')
    if not isinstance(reference_to, (list, tuple, TreeNode)):
        if not reference_to:
            reference_id = get_reference_id(blog_post, 'author')
            reference_type = 'post'
        else:
            reference_id = get_reference_id(reference_to)
            reference_type = 'comment'
        comment_list = get_comments('serial', 'path', post=blog_post.slug, is_spam=False)
        comment_tree = TreeNode()
        current_tree = comment_tree
        for comment in comment_list:
            comment.reply_form = CommentForm(reference_type='comment', reference_to=comment.get_meta().id)
            depth = len(comment.path.split('/')) - 2
            if depth > current_tree.depth:
                current_tree = TreeNode(comment, current_tree, depth)
            elif depth <= current_tree.depth:
                if depth:
                    current_tree = TreeNode(comment, current_tree.parent, depth)
                else:
                    current_tree = TreeNode(comment, comment_tree, depth)
    else:
        comment_tree = reference_to
        reference_type = 'comment'
        reference_id = get_reference_id(reference_to.value)
    return dict(comments=comment_tree.children,
                blog_post=blog_post,
                comment_reply_form=CommentForm(reference_type=reference_type, reference_to=reference_id),
                user=context['user'])
def recent_comments(context):
    rcomments = get_comments('-created_on', is_spam=False)
    return dict(comments=rcomments[:5],
                user=context['user'])
def blog_detail(context):
    return dict(blog_post=context['object'],
                comments=get_comments(reference_to=get_reference_id(context['object'], 'author'), is_spam=False),
                user=context['user'])