Example #1
0
def mybook(request):
    """ 获取我收藏的书 """ 
    profile = request.user.get_profile()
    uid = profile.did
    reading_bids, wish_bids, readed_bids = getUserBooks(uid)
    
    reading = []
    wish = []
    readed = []
    for bid in reading_bids:
        book = getBook(bid)
        if book:
            book.image_link = book.image_link.replace('spic', 'lpic')
            book.like_num = getLikeNumOfBook(bid)
            reading.append(book)

    for bid in wish_bids:
        book = getBook(bid)
        if book:
            book.image_link = book.image_link.replace('spic', 'lpic')
            book.like_num = getLikeNumOfBook(bid)
            wish.append(book)

    for bid in readed_bids:
        book = getBook(bid)
        if book:
            book.image_link = book.image_link.replace('spic', 'lpic')
            book.like_num = getLikeNumOfBook(bid)
            readed.append(book)

    return render_to_response('book/mybook.html',
            {'reading': reading, 'wish': wish, 'readed': readed},
            context_instance=RequestContext(request))
Example #2
0
def ubook(request):
    profile = request.user.get_profile()
    uid = profile.did
    bids = getBookRecommend(uid)    
    paginator = Paginator(bids , 15)
    page = request.GET.get('page')

    try:
        bids_page = paginator.page(page)
    except PageNotAnInteger:
        # 如果页码不是整数,返回第一页.
        bids_page = paginator.page(1)
    except EmptyPage:
        # 如果页码不在范围内,返回最后一页
        bids_page = paginator.page(paginator.num_pages)
    
    books = []
    for bid in bids_page:
        book = getBook(bid)
        if book:
            book.image_link = book.image_link.replace('spic', 'lpic')
            book.like_num = getLikeNumOfBook(bid)
            books.append(book)
    
    return render_to_response('book/ubook.html',
            {'books':books, 'page':bids_page},
            context_instance=RequestContext(request))