コード例 #1
0
ファイル: views.py プロジェクト: varunarora/OC
def build_posts_social(posts, user):
    for post in posts:
        from interactions.CommentUtilities import CommentsBuilder
        from django.contrib.contenttypes.models import ContentType
        comment_ct = ContentType.objects.get_for_model(Comment)
        
        comments_builder = CommentsBuilder(post, comment_ct)
        (post.comments, flatted_post_descendants) = comments_builder.build_tree()

        # Set post upvotes & downvotes
        from interactions.VoteUtilities import VoteUtilities
        post.upvotes = VoteUtilities.get_upvotes_of(post)
        post.downvotes = VoteUtilities.get_downvotes_of(post)

        post.user_in_upvotes = False
        for vote in post.upvotes.all():
            if user == vote.user:
                post.user_in_upvotes = True
                break

        post.user_in_downvotes = False
        for vote in post.downvotes.all():
            if user == vote.user:
                post.user_in_downvotes = True
                break
コード例 #2
0
ファイル: views.py プロジェクト: varunarora/OC
def delete_comment_tree(comment):
    # Get a flat list of all descendant comment, including itself.
    comment_ct = ContentType.objects.get_for_model(Comment)
    from interactions.CommentUtilities import CommentsBuilder

    comments_builder = CommentsBuilder(comment, comment_ct)
    (comment.comments, flatted_comment_descendants) = comments_builder.build_tree()

    for child_comment in flatted_comment_descendants:
        # Delete all votes associated with this comment
        votes = Vote.objects.filter(
            parent_type=comment_ct, parent_id=child_comment.id
        )

        for vote in votes:
            vote.delete()

        child_comment.delete()