Beispiel #1
0
    def get_emoji_counts_for_post_with_id(cls,
                                          post_id,
                                          emoji_id=None,
                                          reactor_id=None):
        PostReaction = get_post_reaction_model()
        Emoji = get_emoji_model()

        emoji_query = Q(reactions__post_id=post_id)

        if emoji_id:
            emoji_query.add(Q(reactions__emoji_id=emoji_id), Q.AND)

        emojis_reacted_with = Emoji.objects.filter(emoji_query).distinct()

        emoji_counts = []

        for emoji in emojis_reacted_with:
            reaction_query = Q(post_id=post_id, emoji_id=emoji.pk)

            if reactor_id:
                reaction_query.add(Q(reactor_id=reactor_id), Q.AND)

            emoji_count = PostReaction.objects.filter(reaction_query).count()
            emoji_counts.append({'emoji': emoji, 'count': emoji_count})

        emoji_counts.sort(key=lambda x: x['count'], reverse=True)

        return emoji_counts
Beispiel #2
0
def check_can_delete_reaction_with_id_for_post(user, post_reaction_id, post):
    check_can_see_post(user=user, post=post)
    # Check if the post belongs to us
    if user.has_post(post=post):
        # Check that the comment belongs to the post
        PostReaction = get_post_reaction_model()
        if not PostReaction.objects.filter(id=post_reaction_id,
                                           post_id=post.pk).exists():
            raise ValidationError(
                _('That reaction does not belong to the specified post.'))
        return

    if not user.post_reactions.filter(id=post_reaction_id).exists():
        raise ValidationError(
            _('Can\'t delete a reaction that does not belong to you.'), )
Beispiel #3
0
    def __init__(self):
        PostReaction = get_post_reaction_model()
        PostComment = get_post_comment_model()
        User = get_user_model()
        Emoji = get_emoji_model()
        Post = get_post_model()
        CommunityInvite = get_community_invite_model()
        Community = get_community_model()

        class NotificationUserSerializer(serializers.ModelSerializer):
            class Meta:
                model = User
                fields = (
                    'id',
                    'username',
                )

        class NotificationEmojiSerializer(serializers.ModelSerializer):
            class Meta:
                model = Emoji
                fields = (
                    'id',
                    'keyword',
                )

        class NotificationPostSerializer(serializers.ModelSerializer):
            class Meta:
                model = Post
                fields = (
                    'id',
                    'uuid',
                )

        class NotificationPostReactionSerializer(serializers.ModelSerializer):
            reactor = NotificationUserSerializer()
            emoji = NotificationEmojiSerializer()
            post = NotificationPostSerializer()

            class Meta:
                model = PostReaction
                fields = ('id', 'reactor', 'emoji', 'post')

        self.NotificationPostReactionSerializer = NotificationPostReactionSerializer

        class NotificationCommunitySerializer(serializers.ModelSerializer):
            class Meta:
                model = Community
                fields = ('id', 'name', 'title')

        class NotificationCommunityInviteSerializer(serializers.ModelSerializer
                                                    ):
            creator = NotificationUserSerializer()
            invited_user = NotificationUserSerializer()
            community = NotificationCommunitySerializer()

            class Meta:
                model = CommunityInvite
                fields = ('id', 'creator', 'invited_user', 'community')

        self.NotificationCommunityInviteSerializer = NotificationCommunityInviteSerializer

        class NotificationPostCommentSerializer(serializers.ModelSerializer):
            commenter = NotificationUserSerializer()
            post = NotificationPostSerializer()

            class Meta:
                model = PostComment
                fields = ('id', 'commenter', 'post')

        self.NotificationPostCommentSerializer = NotificationPostCommentSerializer

        class NotificationPostCommentReplySerializer(
                serializers.ModelSerializer):
            commenter = NotificationUserSerializer()
            post = NotificationPostSerializer()

            class Meta:
                model = PostComment
                fields = ('id', 'commenter', 'post')

        self.NotificationPostCommentReplySerializer = NotificationPostCommentReplySerializer

        class FollowNotificationSerializer(serializers.Serializer):
            following_user = NotificationUserSerializer()

        self.FollowNotificationSerializer = FollowNotificationSerializer

        class ConnectionRequestNotificationSerializer(serializers.Serializer):
            connection_requester = NotificationUserSerializer()

        self.ConnectionRequestNotificationSerializer = ConnectionRequestNotificationSerializer
Beispiel #4
0
def post_reaction_id_exists(post_reaction_id):
    PostReaction = get_post_reaction_model()

    if not PostReaction.objects.filter(id=post_reaction_id).exists():
        raise ValidationError(_('The post reaction does not exist.'), )