Example #1
0
def comments(request, thread_id):
    """
    Returns all comments for thread with thread_id. If hidden param is true,
    returns only hidden comments for aforementioned thread.
    """
    thread = get_object_or_404(Thread, id=thread_id)
    hidden = request.GET.get('hidden', False)

    comments_list = thread.comments.all()

    if hidden:
        comments_list = comments_list.filter(hidden=True)

    hidden_comments_count = comments_list.filter(hidden=True).count()

    comments = paginate_data(request, comments_list)

    bulk_action_form = CommentBulkActionForm()

    return render(
        request, "custom_admin/comments.html", {
            "comments": comments,
            "thread": thread,
            "hidden_comments_count": hidden_comments_count,
            "selected_site": thread.site,
            "bulk_action_form": bulk_action_form,
            "pagination_objects_name": _("comments"),
        })
Example #2
0
def comments(request, thread_id):
    """
    Returns all comments for thread with thread_id. If hidden param is true,
    returns only hidden comments for aforementioned thread.
    """
    thread = get_object_or_404(Thread, id=thread_id)
    hidden = request.GET.get('hidden', False)

    comments_list = thread.comments.all()

    if hidden:
        comments_list = comments_list.filter(hidden=True)

    hidden_comments_count = comments_list.filter(hidden=True).count()

    comments = paginate_data(request, comments_list)

    bulk_action_form = CommentBulkActionForm()

    return render(
        request,
        "custom_admin/comments.html",
        {
            "comments": comments,
            "thread": thread,
            "hidden_comments_count": hidden_comments_count,
            "selected_site": thread.site,
            "bulk_action_form": bulk_action_form,
            "pagination_objects_name": _("comments"),
        }
    )
Example #3
0
def users(request):
    """
    Returns all users if hidden parameter not provided, hidden users if
    hidden parameter is True.
    """
    hidden = request.GET.get('hidden', False)
    user_list = CustomUser.objects.filter(is_staff=False)

    if hidden:
        user_list = user_list.filter(hidden=hidden)

    hidden_users_count = user_list.filter(hidden=True).count()

    users = paginate_data(request, user_list)

    bulk_action_form = UserBulkActionForm()

    return render(
        request,
        "custom_admin/users.html",
        {
            "users": users,
            "hidden_users_count": hidden_users_count,
            "bulk_action_form": bulk_action_form,
            "pagination_objects_name": _("users"),
        }
    )
Example #4
0
def threads(request, site_id=None):
    """
    Fetches and returns threads for a given time period. If site_id not
    provided, threads from first site in DB are returned.
    """
    site = None
    sites = request.user.get_sites()

    if site_id:
        site = get_object_or_404(sites, id=site_id)
    elif request.session.get('last_site_id'):
        site_id = request.session['last_site_id']
        site = get_object_or_404(sites, id=site_id)
    else:
        site = sites[0] if sites.exists() else None

    interval_selection_form = IntervalSelectionForm(request.POST or None)

    date = None
    if interval_selection_form.is_valid():
        date = interval_selection_form.get_date()

    thread_list = Thread.objects.filter(site__in=sites).annotate(
        max_comment_date=Max('comments__created'))

    if date:
        thread_list = thread_list.filter(created__gte=date)

    if site:
        thread_list = thread_list.filter(site=site)

    sort_by = request.GET.get("sort_by", None)

    if sort_by == "thread_date":
        thread_list = thread_list.order_by('-created')
    else:
        list_thread_list = list(thread_list.filter(
                    max_comment_date__isnull=False).order_by('-max_comment_date'))

        list_thread_list += list(thread_list.filter(
                    max_comment_date__isnull=True).order_by('-max_comment_date'))

        thread_list = list_thread_list

    threads = paginate_data(request, thread_list)

    if site:
        request.session['last_site_id'] = site.id

    return render(
        request,
        "custom_admin/threads.html",
        {
            "threads": threads,
            "interval_selection_form": interval_selection_form,
            "sites": sites,
            "selected_site": site,
            "pagination_objects_name": _("articles"),
        }
    )
Example #5
0
def unpublished_comments(request, site_id=None):
    site = None
    sites = request.user.get_sites()

    if site_id:
        site = get_object_or_404(sites, id=site_id)
    elif request.session.get('last_site_id'):
        site_id = request.session['last_site_id']
        site = get_object_or_404(sites, id=site_id)
    else:
        site = sites[0] if sites.exists() else None

    comments_list = Comment.objects.filter(hidden=True, thread__site__id=site_id)
    hidden_comments_count = comments_list.count()

    comments = paginate_data(request, comments_list)

    bulk_action_form = UnpublishedCommentBulkActionForm(initial={'site_id':site.id})

    return render(
        request,
        "custom_admin/unpublished_comments.html",
        {
            "sites": sites,
            "selected_site": site,
            "bulk_action_form": bulk_action_form,
            "comments": comments,
            "hidden_comments_count": hidden_comments_count,
            "pagination_objects_name": _("comments"),
        }
    )
Example #6
0
def threads(request, site_id=None):
    """
    Fetches and returns threads for a given time period. If site_id not
    provided, threads from first site in DB are returned.
    """
    site = None
    sites = request.user.get_sites()

    if site_id:
        site = get_object_or_404(sites, id=site_id)
    elif request.session.get('last_site_id'):
        site_id = request.session['last_site_id']
        site = get_object_or_404(sites, id=site_id)
    else:
        site = sites[0] if sites.exists() else None

    interval_selection_form = IntervalSelectionForm(request.POST or None)

    date = None
    if interval_selection_form.is_valid():
        date = interval_selection_form.get_date()

    thread_list = Thread.objects.filter(site__in=sites).annotate(
        max_comment_date=Max('comments__created'))

    if date:
        thread_list = thread_list.filter(created__gte=date)

    if site:
        thread_list = thread_list.filter(site=site)

    sort_by = request.GET.get("sort_by", None)

    if sort_by == "thread_date":
        thread_list = thread_list.order_by('-created')
    else:
        list_thread_list = list(
            thread_list.filter(
                max_comment_date__isnull=False).order_by('-max_comment_date'))

        list_thread_list += list(
            thread_list.filter(
                max_comment_date__isnull=True).order_by('-max_comment_date'))

        thread_list = list_thread_list

    threads = paginate_data(request, thread_list)

    if site:
        request.session['last_site_id'] = site.id

    return render(
        request, "custom_admin/threads.html", {
            "threads": threads,
            "interval_selection_form": interval_selection_form,
            "sites": sites,
            "selected_site": site,
            "pagination_objects_name": _("articles"),
        })
Example #7
0
def users(request, site_id):
    """
    Returns all users if hidden parameter not provided, hidden users if
    hidden parameter is True.
    """
    site = None
    sites = request.user.get_sites()

    if site_id:
        site = get_object_or_404(sites, id=site_id)
    elif request.session.get('last_site_id'):
        site_id = request.session['last_site_id']
        site = get_object_or_404(sites, id=site_id)
    else:
        site = sites[0] if sites.exists() else None

    hidden = request.GET.get('hidden', False)
    user_list = request.user.get_users()
    if site:
        user_list = user_list.filter(comments__thread__site=site)
        request.session['last_site_id'] = site.id

    if hidden and site:
        user_list = user_list.filter(hidden__in=[site])

    hidden_users_count = user_list.filter(hidden__in=[site]).count()

    users = paginate_data(request, user_list)

    bulk_action_form = UserBulkActionForm()
    return render(
        request,
        "custom_admin/users.html",
        {
            "users": users,
            "hidden_users_count": hidden_users_count,
            "bulk_action_form": bulk_action_form,
            "pagination_objects_name": _("users"),
            "sites": sites,
            "selected_site": site,
        }
    )
Example #8
0
def users(request, site_id):
    """
    Returns all users if hidden parameter not provided, hidden users if
    hidden parameter is True.
    """
    site = None
    sites = request.user.get_sites()

    if site_id:
        site = get_object_or_404(sites, id=site_id)
    elif request.session.get('last_site_id'):
        site_id = request.session['last_site_id']
        site = get_object_or_404(sites, id=site_id)
    else:
        site = sites[0] if sites.exists() else None

    hidden = request.GET.get('hidden', False)
    user_list = request.user.get_users()
    if site:
        user_list = user_list.filter(comments__thread__site=site)
        request.session['last_site_id'] = site.id

    if hidden and site:
        user_list = user_list.filter(hidden__in=[site])

    hidden_users_count = user_list.filter(hidden__in=[site]).count()

    users = paginate_data(request, user_list)

    bulk_action_form = UserBulkActionForm()
    return render(
        request, "custom_admin/users.html", {
            "users": users,
            "hidden_users_count": hidden_users_count,
            "bulk_action_form": bulk_action_form,
            "pagination_objects_name": _("users"),
            "sites": sites,
            "selected_site": site,
        })
Example #9
0
def users(request):
    """
    Returns all users if hidden parameter not provided, hidden users if
    hidden parameter is True.
    """
    hidden = request.GET.get('hidden', False)
    user_list = CustomUser.objects.filter(is_staff=False)

    if hidden:
        user_list = user_list.filter(hidden=hidden)

    hidden_users_count = user_list.filter(hidden=True).count()

    users = paginate_data(request, user_list)

    bulk_action_form = UserBulkActionForm()

    return render(
        request, "custom_admin/users.html", {
            "users": users,
            "hidden_users_count": hidden_users_count,
            "bulk_action_form": bulk_action_form,
            "pagination_objects_name": _("users"),
        })