def show_user_v2(request, uid): user = get_object_or_404(models.User, id=uid) ctx = { 'user': user, 'news': models.CabinetNews.get_user_latest(user, 5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'bookowns': user.book_available()[:LATEST_BOOKS_PER_PAGE], 'mb_page_num': utils.get_page_num(user.book_available().count(), LATEST_BOOKS_PER_PAGE), 'userwanted': user.book_wanted()[:WISH_BOOKS_PER_PAGE], 'wl_page_num': utils.get_page_num(user.book_wanted().count(), WISH_BOOKS_PER_PAGE) } try: if request.user.is_authenticated(): follow = request.user.follow_set.get(following=user) ctx['follow'] = follow except models.Follow.DoesNotExist: pass return render_to_response('cabinet/user_info_v2.html', ctx)
def show_user(request, uid): try: user = models.User.objects.get(id=uid) ctx = {'user': user, 'user_num': models.User.objects.count(), 'book_num': models.BookOwnership.objects.count(), 'borrow_num': models.BookBorrowRecord.objects.count(), 'news': models.CabinetNews.get_user_latest(user, 5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'bookowns': user.book_available(request.user)[:LATEST_BOOKS_PER_PAGE], 'mb_page_num': utils.get_page_num(user.book_available().count(), LATEST_BOOKS_PER_PAGE), 'userwanted': user.book_wanted()[:WISH_BOOKS_PER_PAGE], 'wl_page_num': utils.get_page_num(user.book_wanted().count(), WISH_BOOKS_PER_PAGE) } try: if request.user.is_anonymous(): ctx['is_login'] = False else: ctx['is_login'] = True follow = request.user.follow_set.get(following=user) ctx['remark'] = follow.remark except models.Follow.DoesNotExist: pass return render_to_response('cabinet/user_info.html', ctx) except models.User.DoesNotExist: return HttpResponse("User not found!")
def index(request): ctx = { 'user': request.user, 'user_num': models.User.objects.count(), 'book_num': models.BookOwnership.objects.count(), 'borrow_num': models.BookBorrowRecord.objects.count(), 'news': models.CabinetNews.get_latest(5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'bookowns': models.BookOwnership.objects.filter( ~Q(status=5), Q(visible=1)).order_by('-id')[:LATEST_BOOKS_PER_PAGE], 'page_num': utils.get_page_num( models.BookOwnership.objects.filter(~Q(status=5)).count(), LATEST_BOOKS_PER_PAGE), } ctx.update(csrf(request)) return render_to_response('cabinet/index.html', ctx)
def mybookshelf(request): ctx = {'user': request.user, 'user_num': models.User.objects.count(), 'book_num': models.BookOwnership.objects.filter(~Q(status=5)).count(), 'borrow_num': models.BookBorrowRecord.objects.count(), 'news': models.CabinetNews.get_latest(5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'my_books': request.user.bookownership_set.filter(~Q(status=5))[:5], 'mb_page_num': utils.get_page_num(request.user.bookownership_set.filter(~Q(status=5)).count(), 5), 'loaned_recs': request.user.book_loaned()[:5], 'lr_page_num': utils.get_page_num(len(request.user.book_loaned()), 5), 'borrow_recs': request.user.bookborrowrecord_set.\ order_by('returned_date')[:5], 'br_page_num': utils.get_page_num(request.user.bookborrowrecord_set.count(), 5), 'wanted_books': request.user.book_wanted()[:5], 'wl_page_num': utils.get_page_num(request.user.book_wanted().count(), 5) } ctx.update(csrf(request)) return render_to_response('cabinet/mybookshelf.html', ctx)
def show_user_v2(request, uid): user = get_object_or_404(models.User, id=uid) ctx = {'user': user, 'news': models.CabinetNews.get_user_latest(user, 5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'bookowns': user.book_available()[:LATEST_BOOKS_PER_PAGE], 'mb_page_num': utils.get_page_num(user.book_available().count(), LATEST_BOOKS_PER_PAGE), 'userwanted': user.book_wanted()[:WISH_BOOKS_PER_PAGE], 'wl_page_num': utils.get_page_num(user.book_wanted().count(), WISH_BOOKS_PER_PAGE) } try: if request.user.is_authenticated(): follow = request.user.follow_set.get(following=user) ctx['follow'] = follow except models.Follow.DoesNotExist: pass return render_to_response('cabinet/user_info_v2.html', ctx)
def show_user(request, uid): try: user = models.User.objects.get(id=uid) ctx = { 'user': user, 'user_num': models.User.objects.count(), 'book_num': models.BookOwnership.objects.count(), 'borrow_num': models.BookBorrowRecord.objects.count(), 'news': models.CabinetNews.get_user_latest(user, 5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'bookowns': user.book_available(request.user)[:LATEST_BOOKS_PER_PAGE], 'mb_page_num': utils.get_page_num(user.book_available().count(), LATEST_BOOKS_PER_PAGE), 'userwanted': user.book_wanted()[:WISH_BOOKS_PER_PAGE], 'wl_page_num': utils.get_page_num(user.book_wanted().count(), WISH_BOOKS_PER_PAGE) } try: if request.user.is_anonymous(): ctx['is_login'] = False else: ctx['is_login'] = True follow = request.user.follow_set.get(following=user) ctx['remark'] = follow.remark except models.Follow.DoesNotExist: pass return render_to_response('cabinet/user_info.html', ctx) except models.User.DoesNotExist: return HttpResponse("User not found!")
def index(request): ctx = {'user': request.user, 'user_num': models.User.objects.count(), 'book_num': models.BookOwnership.objects.count(), 'borrow_num': models.BookBorrowRecord.objects.count(), 'news': models.CabinetNews.get_latest(5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'bookowns': models.BookOwnership.objects.filter(~Q(status=5), Q(visible=1)).order_by('-id')[:LATEST_BOOKS_PER_PAGE], 'page_num': utils.get_page_num(models.BookOwnership.objects.filter(~Q(status=5)).count(), LATEST_BOOKS_PER_PAGE), } ctx.update(csrf(request)) return render_to_response('cabinet/index.html', ctx)
def wishlist(request): wishlist = models.BookTagUse.objects.get_empty_query_set() try: wishlist = models.BookTagUse.objects.filter( tag=models.Tag.objects.get(name=u"想借")) except models.Tag.DoesNotExist: pass ctx = {'user': request.user, 'user_num': models.User.objects.count(), 'book_num': models.BookOwnership.objects.count(), 'borrow_num': models.BookBorrowRecord.objects.count(), 'news': models.CabinetNews.get_latest(5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'wishlist': wishlist[:LATEST_BOOKS_PER_PAGE], 'page_num': utils.get_page_num(wishlist.count(), LATEST_BOOKS_PER_PAGE) } ctx.update(csrf(request)) return render_to_response('cabinet/wishlist.html', ctx)
def wishlist(request): wishlist = models.BookTagUse.objects.get_empty_query_set() try: wishlist = models.BookTagUse.objects.filter(tag=models.Tag.objects.get( name=u"想借")) except models.Tag.DoesNotExist: pass ctx = { 'user': request.user, 'user_num': models.User.objects.count(), 'book_num': models.BookOwnership.objects.count(), 'borrow_num': models.BookBorrowRecord.objects.count(), 'news': models.CabinetNews.get_latest(5), 'actives': models.User.objects.order_by('-last_login')[:12], 'weibo_auth': get_weibo_client().get_authorize_url(), 'wishlist': wishlist[:LATEST_BOOKS_PER_PAGE], 'page_num': utils.get_page_num(wishlist.count(), LATEST_BOOKS_PER_PAGE) } ctx.update(csrf(request)) return render_to_response('cabinet/wishlist.html', ctx)
def userbook_v2(request, uid, page): user = models.User.objects.get(id=uid) page_num = utils.get_page_num(user.book_available().count(), LATEST_BOOKS_PER_PAGE) return books_get_page(request, page, page_num, 'userbook_' + uid, 2)
def books_wish(request, page): page_num = utils.get_page_num(utils.get_wishlist().count(), 5) return books_get_page(request, page, page_num, 'wish')
def books_wanted(request, page): page_num = utils.get_page_num(len(request.user.book_wanted()), 5) return books_get_page(request, page, page_num, 'wanted')
def books_borrowed(request, page): page_num = utils.get_page_num(request.user.bookborrowrecord_set.count(), 5) return books_get_page(request, page, page_num, 'borrowed')
def books_mybooks(request, page): page_num = utils.get_page_num(request.user.bookownership_set.count(), 5) return books_get_page(request, page, page_num, 'mybooks')
def books_latest(request, page): page_num = utils.get_page_num(models.BookOwnership.objects.count(), LATEST_BOOKS_PER_PAGE) return books_get_page(request, page, page_num, 'latest')
def userwanted_v2(request, uid, page): user = models.User.objects.get(id=uid) page_num = utils.get_page_num(len(user.book_wanted()), WANTED_BOOKS_PER_PAGE) return books_get_page(request, page, page_num, 'userwanted_' + uid, 2)