class UserProfilePlainSerializer(serializers.ModelSerializer):
    auth_user = AuthUserSerializerLogin(read_only=True)

    class Meta:
        model = UsersProfile
        fields = ('auth_user',)
        read_only_fields = ('slug',)
class ActivitySerializer(serializers.ModelSerializer):
    like_count = serializers.ReadOnlyField()
    url = serializers.SerializerMethodField()
    share_count = serializers.ReadOnlyField()
    company = CompanySerializer(read_only=True)
    dislike_count = serializers.ReadOnlyField()
    comments_count = serializers.ReadOnlyField()
    auth_user = AuthUserSerializerLogin(read_only=True)
    is_friends = serializers.SerializerMethodField()
    liked = serializers.SerializerMethodField('is_liked')
    author_settings = serializers.SerializerMethodField()
    shared = serializers.SerializerMethodField('is_shared')
    disLiked = serializers.SerializerMethodField('is_disliked')
    bookmarked = serializers.SerializerMethodField('is_bookmarked')
    original_activity = RecursiveActivitySerializer(read_only=True)
    activity_mention = ListActivityMentionSerializer(many=True, read_only=True)
    activity_attachment = ActivityAttachmentSerializers(many=True,
                                                        read_only=True)

    def is_shared(self, obj):
        return obj.activity_action.filter(
            has_share=True, auth_user=self.context['request'].user).exists()

    def is_liked(self, obj):
        return obj.activity_action.filter(
            has_like=True, auth_user=self.context['request'].user).exists()

    def is_disliked(self, obj):
        return obj.activity_action.filter(
            has_dislike=True, auth_user=self.context['request'].user).exists()

    def is_bookmarked(self, obj):
        return obj.activity_control.filter(
            is_saved=True, auth_user=self.context['request'].user).exists()

    def get_url(self, obj):
        return self.context['request'].build_absolute_uri(
            location="/") + obj.get_absolute_url()[1:]

    def get_is_friends(self, obj):
        try:
            return Friend.objects.are_friends(self.context['request'].user,
                                              obj.auth_user)
        except:
            return False

    def get_author_settings(self, obj):
        instance = ProfileSettings.objects.get(
            user_profile__auth_user=obj.auth_user)
        return UserProfileSettingsSerializer(instance=instance,
                                             context={
                                                 'request':
                                                 self.context['request']
                                             }).data

    class Meta:
        model = Activity
        fields = '__all__'
        read_only_fields = ('action', 'liked', 'disLiked', 'is_friends',
                            'author_settings')
class ActivityCommentSerializer(serializers.ModelSerializer):
    comment_thread = RecursiveSerializer(many=True, read_only=True)
    auth_user = AuthUserSerializerLogin(read_only=True)
    comment_mention = ListCommentMentionSerializer(many=True, read_only=True)

    class Meta:
        model = Comments
        fields = '__all__'
        read_only_fields = (
            'auth_user',
            'activity',
        )
Beispiel #4
0
 def get(self, request, pk, formate=None):
     get_object_or_404(Activity, pk=pk)
     paginator = PageNumberPagination()
     paginator.page_size = 10
     activity_action = ActivitySocialAction.objects.filter(activity_id=pk,
                                                           has_dislike=True)
     auth_users = [u.auth_user for u in activity_action]
     result_page = paginator.paginate_queryset(auth_users, request)
     data = AuthUserSerializerLogin(instance=result_page,
                                    many=True,
                                    context={
                                        'request': request
                                    }).data
     return paginator.get_paginated_response(data)
Beispiel #5
0
 def get(self, request, slug, formate=None):
     paginator = PageNumberPagination()
     paginator.page_size = 10
     friends = Friend.objects.unread_requests(user=request.user)
     if friends:
         friends = [friend.from_user for friend in friends]
         result_page = paginator.paginate_queryset(friends, request)
         data = AuthUserSerializerLogin(instance=result_page,
                                        many=True,
                                        context={
                                            'request': request
                                        }).data
         return paginator.get_paginated_response(data)
     else:
         raise DataNotFoundException
     return Response(status=HTTP_500_INTERNAL_SERVER_ERROR)
Beispiel #6
0
 def get(
     request,
     slug,
 ):
     paginator = PageNumberPagination()
     paginator.page_size = 10
     profile = get_object_or_404(UsersProfile, slug=slug)
     friends = Friend.objects.friends(profile.auth_user)
     if 'query' in request.GET and len(request.GET['query']) > 3:
         friends = [
             x for x in friends
             if request.GET['query'] in x.first_name + ' ' + x.last_name
         ]
     if friends:
         result_page = paginator.paginate_queryset(friends, request)
         data = AuthUserSerializerLogin(instance=result_page,
                                        many=True,
                                        context={
                                            'request': request
                                        }).data
         return paginator.get_paginated_response(data)
     else:
         raise DataNotFoundException
     return Response(status=HTTP_500_INTERNAL_SERVER_ERROR)
class ListActivityMentionSerializer(serializers.ModelSerializer):
    auth_user = AuthUserSerializerLogin(read_only=True)

    class Meta:
        model = ActivityMention
        fields = ('auth_user', )