def cat_drop(request, isbn): check_login(request) user = User.objects.get(username=request.session['username']) try: book = Books.objects.get(ISBN=isbn) user.remove_from_order(book) except Books.DoesNotExist: pass return redirect('library:cart')
def list_by_cate(request, cid=0): check_login(request) category = get_all_cate() books = get_list_by_cate(cid) # print(books[0].cover) return render(request, 'library/store.html', locals())
def add_to_cart(request, isbn): check_login(request) amount = int(request.POST['amount']) if amount <= 0: return redirect('library:book_detail') book = Books.objects.get(ISBN=isbn) user = User.objects.get(username=request.session['username']) user.add_to_cart(book, amount) return redirect('library:index')
def search_result(request): check_login(request) category = get_all_cate() key = request.POST['keyword'] if len(key): books = Books.objects.filter( Q(ISBN__contains=key) | Q(title__contains=key) | Q(author__contains=key) | Q(publisher__contains=key)) else: books = Books.objects.all() return render(request, 'library/search_result.html', locals())
def book_detail(request, ISBN): check_login(request) if len(ISBN) != 11: return redirect('library:index') try: book = Books.objects.get(ISBN=ISBN) except Books.DoesNotExist: return redirect('library:index') else: context = {'book': book} return render(request, 'library/book_detail.html', context)
def index(request): check_login(request) books = get_list_by_cate(0) category = get_all_cate() return render(request, 'library/index.html', locals())
def do_pay(request): check_login(request) username = request.session['username'] user = User.objects.get(username=username) user.pay() return redirect('library:index')
def cart_contain(request): check_login(request) category = get_all_cate() user = User.objects.get(username=request.session['username']) orders = user.get_all_order() return render(request, 'library/cart.html', locals())