Esempio n. 1
0
def index_view(request):
    t = request.GET.get('t', None)
    if request.user.is_authenticated and t == 'all':

        p = Post.objects.filter(published_at__lt=timezone.now()).order_by('-published_at')
        page = request.GET.get('page', 1)
        posts, page_of_paginator = pagination_helper(p, page, 5)

        query_string_prefix="t=all&"
        return render(request, 'main/index_all.html', {'items': posts, 
            'query_string_prefix': query_string_prefix, 'page_of_paginator':page_of_paginator})

    elif request.user.is_authenticated: 
        
        # default is showing posts of whom the user is following
        u = request.user.follow.all()
        p = Post.objects.filter(published_at__lt=timezone.now()).filter(
            creator__in=u).order_by('-published_at')
        page = request.GET.get('page', 1)
        posts, page_of_paginator = pagination_helper(p, page, 5)
        return render(request, 'main/index.html', {'items': posts,
            'page_of_paginator': page_of_paginator})

    else:
        # provide limited number(20) of posts to anonymous user
        p = Post.objects.filter(published_at__lt=timezone.now()).order_by('-published_at')[:15]
        page = request.GET.get('page', 1)
        posts, page_of_paginator = pagination_helper(p, page, 5)
        return render(request, 'main/index_all.html', {'items': posts,
            'page_of_paginator': page_of_paginator})
Esempio n. 2
0
def panel_users_following_me(request):

    object_list = request.user.fans.exclude(id__exact=request.user.id)

    page = request.GET.get('page', 1)
    items, page_of_paginator = pagination_helper(object_list, page)
    return render(request, 'panel/users_following_me.html', {
        'items': items,
        'page_of_paginator': page_of_paginator
    })
Esempio n. 3
0
def panel_comments_sent(request):

    object_list = Comment.objects.filter(
        creator=request.user).order_by('-created_at')

    page = request.GET.get('page', 1)
    items, page_of_paginator = pagination_helper(object_list, page)
    return render(request, 'panel/comments_sent.html', {
        'items': items,
        'page_of_paginatior': page_of_paginator
    })
Esempio n. 4
0
def panel_comments_rcvd(request):

    posts = request.user.post_set.order_by('-created_at')
    object_list = Comment.objects.filter(post__in=posts).exclude(
        creator__exact=request.user).order_by('-created_at')

    page = request.GET.get('page', 1)
    items, page_of_paginator = pagination_helper(object_list, page)
    return render(request, 'panel/comments_rcvd.html', {
        'items': items,
        'page_of_paginator': page_of_paginator
    })
Esempio n. 5
0
def user_view(request, username):
    u = get_object_or_404(User, username=username)
    all_posts = u.post_set.filter(
        published_at__lt=timezone.now()).order_by('-created_at')

    page = request.GET.get('page', 1)
    posts, page_of_paginator = pagination_helper(all_posts, page, 5)

    return render(request, 'user/view.html', {
        'display_user': u,
        'items': posts,
        'page_of_paginator': page_of_paginator
    })
Esempio n. 6
0
def panel_drafts(request):

    object_list = request.user.post_set.exclude(
        published_at__lt=timezone.now()).order_by('-created_at')

    page = request.GET.get('page', 1)

    items, page_of_paginator = pagination_helper(object_list, page)

    return render(request, 'panel/drafts.html', {
        'items': items,
        'page_of_paginator': page_of_paginator
    })