当前位置: 首页>>代码示例>>Python>>正文


Python Cart.set_quantity方法代码示例

本文整理汇总了Python中carton.cart.Cart.set_quantity方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.set_quantity方法的具体用法?Python Cart.set_quantity怎么用?Python Cart.set_quantity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在carton.cart.Cart的用法示例。


在下文中一共展示了Cart.set_quantity方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: show

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import set_quantity [as 别名]
def show(request):
	cart = Cart(request.session)	
	if request.method == 'POST':
		print 'mpike mesa sto post'
		isbn = request.POST.get("book_isbn",'')
		quant = request.POST.get("book_new_quant",'')
		product = Book.objects.get(isbn=isbn)
		cart.set_quantity(product, quantity=quant)
	return render(request, 'shopping/show-cart.html')
开发者ID:NickLont,项目名称:bookstore,代码行数:11,代码来源:views.py

示例2: show

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import set_quantity [as 别名]
def show(request):
    cart = Cart(request.session)
    if request.method == 'POST':
        quantitylist = request.POST.getlist('quantity[]')
        for idx, item in enumerate(cart.products):
            item = Item.objects.get(id=item.id)
            cart.set_quantity(item, quantitylist[idx])
        return redirect(reverse('checkout:page'))
    return render(request, 'shopping/show-cart.html')
开发者ID:YuMingChang,项目名称:MMCB,代码行数:11,代码来源:views.py

示例3: decrementar_quantidade

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import set_quantity [as 别名]
def decrementar_quantidade(request):
    produto_id = request.POST['produto']
    quantidade = request.POST['quantidade']
    carrinho = Cart(request.session)
    produto = Produto.objects.get(pk=produto_id)
    carrinho.set_quantity(produto, quantity=quantidade)
    template = loader.get_template('loja/carrinho.html')
    context = RequestContext(request)
    return HttpResponse(template.render(context))
开发者ID:pydawan,项目名称:protetores_bucais,代码行数:11,代码来源:views.py

示例4: post

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import set_quantity [as 别名]
    def post(self, request):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)

        cart = Cart(request.session)
        product = get_object_or_404(Product, id=serializer.data['product_id'])
        cart.set_quantity(product, quantity=serializer.data['product_quantity'])

        response_data = {
            'detail': 'Product was updated.'
        }
        response_status = status.HTTP_201_CREATED

        return Response(response_data, status=response_status)
开发者ID:scentrade,项目名称:website,代码行数:16,代码来源:views.py

示例5: CartTests

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import set_quantity [as 别名]

#.........这里部分代码省略.........

        response = self.show_response()

        self.assertContains(response, 'items count: 3')
        self.assertContains(response, 'unique count: 2')

    def test_products_are_removed_all_together(self):
        """
        Can all products of a single type be removed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        self.cart.remove(self.deer)

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertContains(response, 'moose')

    def test_single_product_is_removed(self):
        """
        Can a single instance of a product be removed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.session.save()

        self.cart.remove_single(self.deer)

        self.assertContains(self.show_response(), '2 deer')

    def test_quantity_is_overwritten(self):
        """
        Can an items quantity be changed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.session.save()

        self.cart.set_quantity(self.deer, 4)

        self.assertContains(self.show_response(), '4 deer')

    def test_cart_items_are_cleared(self):
        """
        Can a cart be entirely cleared?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.moose, 20.00, 1)
        self.cart.clear()
        self.session.save()

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertNotContains(response, 'moose')

    @override_settings(CART_PRODUCT_LOOKUP={'price__gt': 1})
    def test_custom_product_filter_are_applied(self):
        """
        We modify the cart queryset to exclude some products. We
        should not be able to add excluded products to the cart.
        """
        exclude = Product.objects.create(
            name='EXCLUDED',
            price=0.99,
            custom_id=100,
        )

        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(exclude, exclude.price, 1)
        self.session.save()

        response = self.show_response()

        self.assertNotContains(response, 'EXCLUDE')
        self.assertContains(response, 'deer')

    def test_get_model_product_path(self):
        """
        Is a string with the full, correct import path returned for a
        model?
        """
        self.assertEqual(
            self.cart.get_product_model_path(self.deer),
            'carton.tests.models.Product',
        )

    def test_different_product_models(self):
        """
        Does the cart work with different models?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.ticket, 25.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, '1 deer for $10.0')
        self.assertContains(response, '1 Clint Mansell for $25.0')
开发者ID:Matt-Deacalion,项目名称:django-carton,代码行数:104,代码来源:tests.py

示例6: set_quantity

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import set_quantity [as 别名]
def set_quantity(request):
    cart = Cart(request.session)
    product = Product.objects.get(pk=request.POST.get('product_id'))
    quantity = request.POST.get('quantity')
    cart.set_quantity(product, quantity)
    return HttpResponse()
开发者ID:50c10,项目名称:django-carton,代码行数:8,代码来源:views.py

示例7: set_quantity

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import set_quantity [as 别名]
def set_quantity(request):
    cart = Cart(request.session)
    product = products[int(request.POST.get('product_id'))]
    quantity = request.POST.get('quantity')
    cart.set_quantity(product, quantity)    
    return HttpResponse()
开发者ID:jongabriel,项目名称:django-carton,代码行数:8,代码来源:views.py


注:本文中的carton.cart.Cart.set_quantity方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。