Exemple #1
0
def thread_list(request, filter_str=None, page=1, form=None):
    thread_qs = Thread.objects.active()
    filter_str, filtered_qs = get_filtered_threads_for_page(
        request, filter_str, thread_qs, request.user)
    thread_paginator = get_paginated_queryset(filtered_qs, THREAD_PER_PAGE,
                                              page)
    form_action = reverse('threads:thread_create',
                          kwargs={
                              'filter_str': filter_str,
                              'page': page
                          })
    home_url = Thread.get_precise_url(filter_str, page)
    base_url = [f"/threads/{filter_str}/", "/"]
    ctx = {
        'threads': thread_paginator,
        'base_url': base_url,
        'show_floating_btn': True,
        'login_redirect_url': get_post_login_redirect_url(home_url),
        'form': ThreadForm if not form else form,
        'is_post_update': True if form else False,
        'form_action': form_action + '#post-form',
        'current_thread_filter': filter_str
    }
    add_pagination_context(base_url, ctx, thread_paginator)
    return render(request, 'home.html', ctx)
Exemple #2
0
def user_comment_list(request, username):
    user = get_object_or_404(User, username=username)
    comment_qs = Comment.objects.get_pure_and_thread_active_for_user(user)
    comments = get_paginated_queryset(comment_qs, 10, request.GET.get('page'))
    url = reverse('accounts:user_comments', kwargs={'username': username})
    base_url = [f'{url}?page=', '']
    ctx = {
        'comments': comments,
        'base_url': base_url,
        'current_profile_page': 'replies',
        'userprofile': user
    }
    add_pagination_context(base_url, ctx, comments)
    return render(request, 'accounts/profile_comments.html', ctx)
Exemple #3
0
def user_thread_list(request, username, filter_str, page):
    user = get_object_or_404(User, username=username)
    if not user.is_required_filter_owner(request.user, filter_str):
        raise Http404
    thread_qs = Thread.objects.active()
    filter_str, filtered_qs = get_filtered_threads_for_profile(request,
                                                               filter_str,
                                                               thread_qs,
                                                               user=user)
    thread_paginator = get_paginated_queryset(filtered_qs, 10, page)
    base_url = [f'/accounts/{username}/{filter_str}/', '/']
    ctx = {
        'userprofile': user,
        'threads': thread_paginator,
        'base_url': base_url,
        'current_profile_page': filter_str
    }
    add_pagination_context(base_url, ctx, thread_paginator)
    return render(request, 'accounts/profile_threads.html', ctx)
Exemple #4
0
def user_notification_list(request, username):
    page = request.GET.get('page')
    notif_qs = Notification.objects.get_for_user(request.user)
    notifs = get_paginated_queryset(notif_qs, 3, page)
    notif_id_list = [notif.pk for notif in notifs]
    Notification.objects.mark_as_read(request.user, notif_id_list)
    notif_url, notif_count = Notification.objects.get_receiver_url_and_count(
        request.user)
    request.user.update_notification_info(request, notif_url, notif_count)

    base_url = [f'/accounts/{request.user.username}/notifications/?page=', '']
    ctx = {
        'userprofile': request.user,
        'current_profile_page': 'user_notifs',
        'notifications': notifs,
        'base_url': base_url
    }
    add_pagination_context(base_url, ctx, notifs)

    return render(request, 'accounts/profile_notif.html', ctx)
Exemple #5
0
def get_comment_paginator(request, thread):
    comment_qs = Comment.objects.get_for_thread(thread)
    page_num = request.GET.get('page')
    return get_paginated_queryset(comment_qs, COMMENT_PER_PAGE, page_num)