Esempio n. 1
0
def user_bookmarks(request):
    '''
    --All user bookmarked posts--
    ==========================================================================================================
    Returns all posts a user has bookmarked. Paginates the queryset.
    ==========================================================================================================
    '''
    user_bookmarks = Post.objects.filter(bookmarks=request.user,
                                         is_active=True)
    all_user_bookmarks = get_paginated_queryset(request, user_bookmarks,
                                                PostOverviewSerializer)
    return all_user_bookmarks
Esempio n. 2
0
def user_posts(request):
    '''
    --All user posts view--
    ==========================================================================================================
    Returns nested representations of all posts for this user. Paginates the quereyset.
    ==========================================================================================================
    '''
    posts_to_paginate = \
        Post.objects.prefetch_related('bookmarks').select_related('previouspost').select_related('nextpost').filter(author=request.user, is_active=True)
    all_posts = get_paginated_queryset(request, posts_to_paginate,
                                       PostOverviewSerializer)

    return all_posts
Esempio n. 3
0
def user_followers(request):
    '''
    --All user followers view--
    ==========================================================================================================
    Returns all users that are following him. Paginates the queryset.
    ==========================================================================================================
    '''
    user_followers = request.user.followers.all()

    all_followers = get_paginated_queryset(request,
                                           user_followers,
                                           UserFollowingSerializer,
                                           page_size=30)

    return all_followers
Esempio n. 4
0
def user_following(request):
    '''
    --All user following view--
    ==========================================================================================================
    Returns all users a user is folllowing. Paginates the queryset.
    ==========================================================================================================
    '''
    user_followings = request.user.following.all()

    all_followings = get_paginated_queryset(request,
                                            user_followings,
                                            UserFollowingSerializer,
                                            page_size=30)

    return all_followings
Esempio n. 5
0
def user_dislikes(request):
    '''
    --All posts liked view--
    ==========================================================================================================
    Returns all posts liked by a user. Paginates the queryset.
    ==========================================================================================================
    '''
    user = request.user
    user_disliked_posts = DisLike.objects.filter(users=user)
    disliked_posts = []
    for dislike in user_disliked_posts:
        if not dislike.post.is_active:
            continue
        disliked_posts.append(dislike.post)

    all_disliked_posts = get_paginated_queryset(request, disliked_posts,
                                                PostOverviewSerializer)
    return all_disliked_posts
Esempio n. 6
0
def user_follower_posts(request):
    '''
    --All user following posts view--
    ==========================================================================================================
    Returns all post by those hes following. Paginates the queryset.
    ==========================================================================================================
    '''
    user_followers = request.user.followers.all()

    posts = []

    for follow in user_followers:
        follow_posts = Post.objects.filter(author=follow.user.id,
                                           is_active=True)
        for post in follow_posts:
            posts.append(post)

    all_followers_posts = get_paginated_queryset(request, posts,
                                                 PostOverviewSerializer)

    return all_followers_posts