views.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:bbgo 作者: genonfire 项目源码 文件源码
def dashboard_comment(request, status='all', page=1):
    """Dashboard comment"""
    list_count = settings.DASHBOARD_LIST_COUNT

    if int(page) < 1:
        return redirect('blogs:dashboard_comment', status, 1)

    current_page = int(page) - 1
    start_at = current_page * list_count
    end_at = start_at + list_count

    if status == 'all':
        q = Q()
    else:
        q = Q(status__iexact=status)

    total = Comment.objects.filter(q).count()
    lists = Comment.objects.filter(q).order_by('-id')[start_at:end_at]

    count_all = Comment.objects.count()
    count_normal = Comment.objects.filter(status__iexact='1normal').count()
    count_deleted = Comment.objects.filter(status__iexact='6deleted').count()
    count_spam = Comment.objects.filter(status__iexact='7spam').count()

    index_total = int(ceil(float(total) / list_count))
    index_begin = (current_page / 10) * 10 + 1
    index_end = mindex_end = index_total
    if index_end - index_begin >= 10:
        index_end = index_begin + 9
    mindex_begin = (current_page / 5) * 5 + 1
    if mindex_end - mindex_begin >= 5:
        mindex_end = mindex_begin + 4

    return render(
        request,
        "blogs/dashboard_comment.html",
        {
            'lists': lists,
            'total': total,
            'page': current_page + 1,
            'index_begin': index_begin,
            'index_end': index_end + 1,
            'mindex_begin': mindex_begin,
            'mindex_end': mindex_end + 1,
            'index_total': index_total,
            'status': status,
            'count_all': count_all,
            'count_normal': count_normal,
            'count_deleted': count_deleted,
            'count_spam': count_spam,
        }
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号