Beispiel #1
0
def cart_add(request, book_id):
    book = get_object_or_404(Book, id=book_id)
    cart = Cart(request)
    form = CartAddBookForm(request.POST)
    if form.is_valid():
        cd = form.cleaned_data
        cart.add(book=book,
                 quantity=cd['quantity'],
                 update_quantity=cd['update'])
    return redirect('cart_detail')
Beispiel #2
0
def book_detail(request, id, slug):
    book = get_object_or_404(Book, id=id, slug=slug, available=True)
    cart_book_form = CartAddBookForm()
    return render(request,
                  'library/books/detail.html',
                  {'book': book,
                   'cart_book_form': cart_book_form})
Beispiel #3
0
def book_detail(request, pk):
    book = get_object_or_404(Book,
                             pk=pk,
                             )
    cart_book_form = CartAddBookForm()
    return render(request, 'shop/book_detail.html', {'book': book,
                                                     'cart_book_form': cart_book_form})
Beispiel #4
0
def book_list(request, category_slug=None):
    search_form = SearchForm()
    query = None
    category = None
    categories = Category.objects.all()
    books = Book.objects.filter(available=True)
    cart_book_form = CartAddBookForm()
    if 'query' in request.GET:
        form = SearchForm(request.GET)
        if form.is_valid():
            query = form.cleaned_data['query']
            books = Book.objects.annotate(search=SearchVector(
                'title', 'author'), ).filter(search=query)
    if category_slug:
        category = get_object_or_404(Category, slug=category_slug)
        books = books.filter(category=category)
    return render(
        request, 'shop/book/list.html', {
            'books': books,
            'category': category,
            'categories': categories,
            'cart_book_form': cart_book_form,
            'search_form': search_form,
            'query': query
        })
Beispiel #5
0
    def get(self, *args, **kwargs):
        request = self.request
        slug = self.kwargs.get('slug')

        try:
            data = get_object_or_404(Book, slug=slug)
            cart_book_form = CartAddBookForm(id=data.id)
        except Book.DoesNotExist:
            raise Http404("Not Found!!!")
        except Book.MultipleObjectsReturned:
            queryset = Book.objects.filter(slug=slug)
            data = queryset.first()
            cart_book_form = CartAddBookForm(id=data.id)
        return render(request, 'book_detail_slug_view.html', {
            'book': data,
            'cart_book_form': cart_book_form
        })
Beispiel #6
0
def cart_detail(request):
    cart = Cart(request)
    for item in cart:
        item['update_quantity_form'] = CartAddBookForm(
            initial={
                'quantity': item['quantity'],
                'update': True
            })
    context = {'cart': cart}
    return render(request, 'cart/cart_detail.html', context)
Beispiel #7
0
def book_detail(request, id, slug):
    book = get_object_or_404(Book, id=id, slug=slug, available=True)
    book_category = get_object_or_404(Category, name=book.category)
    cart_book_form = CartAddBookForm()
    return render(
        request, 'shop/book/detail.html', {
            'book': book,
            'book_category': book_category,
            'cart_book_form': cart_book_form
        })
Beispiel #8
0
def product_list(request, category_pk):
    context = {}
    categories = Category.objects.all()
    category = get_object_or_404(Category, pk=category_pk)
    products = Product.objects.filter(category_id=category_pk)
    cart_form = CartAddBookForm()
    context['category'] = category
    context['products'] = products
    context['categories'] = categories
    context['cart_form'] = cart_form
    return render(request, 'product/product_list.html', context)
Beispiel #9
0
def product_detail(request, product_pk):
    context = {}
    categories = Category.objects.all()
    product = get_object_or_404(Product, pk=product_pk)
    cart_form = CartAddBookForm()
    context['product'] = product
    context['categories'] = categories
    context['cart_form'] = cart_form

    # all_pages_count =product.all().count()
    # #current_page = page_info  # 获取用户当前想要访问的页码
    # if current_page is None:
    #     current_page = 1
    # # 每页显示的记录个数
    # per_page = 3
    # base_url = '/product/product_list/'
    # # 用自定义的分页器生成每页对象
    # page_info = PageInfo(current_page, all_pages_count, per_page, base_url, c_id)
    # # 每页显示的记录的起始位置
    # products = product.all()[page_info.start(): page_info.end()]
    # context['products'] = products
    # context['page_info'] = page_info

    return render(request, 'product/product_details.html', context)
Beispiel #10
0
def book_detail_view(request, pk=None, *args, **kwargs):
    # instance = Book.objects.get(pk=pk)
    instance = get_object_or_404(Book, pk=pk)
    cart_book_form = CartAddBookForm(id=pk)
    context = {'object': instance, 'cart_book_form': cart_book_form}
    return render(request, 'book_detail_view.html', context)
Beispiel #11
0
def book_detail(request, book_id, book_slug):
    book = get_object_or_404(Book, id=book_id, slug=book_slug, available=True)
    form = CartAddBookForm()
    context = {'book': book, 'form': form}
    return render(request, 'shop/book_detail.html', context)
Beispiel #12
0
def BookDetail(request, iD, slug):
    book = get_object_or_404(Book, id=iD, slug=slug, available=True)
    cart_book_form = CartAddBookForm()
    return render_to_response('shop/book_detail.html',
                              {'book': book,
                               'cart_book_form': cart_book_form})