示例#1
0
def pagingAll(request):
    '''处理首页所有书籍分页, ajax request only'''
    if not request.is_ajax():
        raise Http404
    
    cateName = request.REQUEST.get('cateName', 'all')
    ctx = {'cateName': cateName}
    
    pageNo = pages.getRequestPageNo(request)
    request.session['currentPageNo'] = pageNo
    paging = pages.getSessionPaging(request, _getDataKey('cate'))
    if not paging:
        if cateName == 'all':
            books = Book.objects.getAll()
        else:
            category = Category.objects.get(name=cateName)
            books = Book.objects.filter(category=category)
            
        paging = initSessionBooklistPaging(request, _getDataKey('cate'), books, BOOK_PAGE_SIZE)
    
    ctx.update(paging.result(pageNo))
    t = get_template('base/books_list.html')
    html = t.render(RequestContext(request, ctx))
    
    return HttpResponse(json.dumps({'status': 'success', 'html': html}))
示例#2
0
def pagingBooks(request, type):
    '''处理书籍查询结果分页, ajax request only'''
    if not request.is_ajax():
        raise Http404
    
    pageNo = pages.getRequestPageNo(request)
    request.session['currentPageNo'] = pageNo
    paging = pages.getSessionPaging(request, _getDataKey(type))
    if not paging:
        booklist = Book.objects.all()
        paging = initSessionBooklistPaging(request, _getDataKey(type), booklist, BOOK_PAGE_SIZE)
    
    t = get_template('books/includes/resultlist.html')
    html = t.render(RequestContext(request, paging.result(pageNo)))
    
    return HttpResponse(json.dumps({'status': 'success', 'html': html}))
示例#3
0
def pagingOrders(request):
    '''分页订单, ajax request only'''
    if not request.is_ajax():
        raise Http404
    
    profile = request.user.get_profile()
    
    pageNo = pages.getRequestPageNo(request)
    request.session['currentPageNo'] = pageNo
    paging = pages.getSessionPaging(request, 'orderData')
    if not paging:
        orderlist = profile.getOrders().exclude(id__in=profile.delOrderIds)
        paging = initSessionOrderlistPaging(request, 'orderData', orderlist, 5)
    
    t = get_template('profiles/includes/order_list.html')
    html = t.render(RequestContext(request, paging.result(pageNo)))
    
    return HttpResponse(json.dumps({'status': 'success', 'html': html}))
示例#4
0
def pagingCmts(request, bookId):
    '''处理书籍评论分页, ajax request only'''
    if not request.is_ajax():
        raise Http404
    
    book = _getBookById(bookId)
    pageNo = pages.getRequestPageNo(request)
    
    request.session['currentPageNo'] = pageNo
    paging = pages.getSessionPaging(request, CMT_DATA_KEY)
    if not paging:
        cmts = book.getComments()
        paging = initSessionCmtlistPaging(request, CMT_DATA_KEY, cmts, CMT_PAGE_SIZE)
    
    t = get_template('books/includes/comments.html')
    ctx = paging.result(pageNo)
    html = t.render(RequestContext(request,ctx))
    
    return HttpResponse(json.dumps({'status': 'success', 'html': html}))
示例#5
0
def pagingBookCmts(request, bookId):
    ''''''
    if not request.is_ajax():
        raise Http404
    
    book = _getBookById(bookId)
    pageNo = pages.getRequestPageNo(request)
    column = request.REQUEST.get("column", '')
    
    request.session['currentPageNo'] = pageNo
    paging = pages.getSessionPaging(request, _getCmtsDataKey(column))
    if not paging:
        cmtList = book.getComments()
        paging = initSessionCmtlistPaging(request, _getCmtsDataKey(column), cmtList, 5)
    
    t = get_template('books/includes/cmtlist_%s.html' % column)
    return HttpResponse(json.dumps({'status': "success", 
        'html': t.render(RequestContext(
         request, paging.result(pageNo, 
               pageItemsKey=column+"PageItems",
               pageRangeKey=column+"PageRange",
    )))}))