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


Python Cart.clear方法代码示例

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


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

示例1: pago

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def pago(request):
	if request.method == "POST":
		cart = Cart(request.session)
		if not cart.is_empty:
			#
			#	Guardo el pedido
			# ===========================
			
			# creo un pedido con los datos del cliente y el restaurante
			restaurante =cart.items[0].product.restaurante
			cliente = Cliente.objects.get(user=request.user) #falta el cliente
			pedido = Pedido (restaurante=restaurante, cliente=cliente)
			pedido.save()
			
			#aado platos al pedido
			for item in cart.items:
				plato = item.product
				Detalle_pedido(plato=plato, pedido=pedido, cantidad=item.quantity).save()
						
			

			if request.POST.get('pago') == "Paypal":
				return paypal_create(request)
			elif request.POST.get('pago') == "Efectivo":
				cart.clear() #Se vacia el carrito
				return HttpResponseRedirect(reverse('pago_exitoso'))
开发者ID:gamezinfantes,项目名称:UFood,代码行数:28,代码来源:views.py

示例2: empty_cart

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def empty_cart(request):
	cart = Cart(request.session)
	cart.clear()
	html = new_cart_html(request,1)
	cart_contents_qty = cart_contents_empty(request)
	payload = update_cart_status_and_prepare_payload(request, html, cart_contents_qty)
	return HttpResponse(json.dumps(payload), content_type="application/json")
开发者ID:vlameiras,项目名称:cdkeyswholesale,代码行数:9,代码来源:views.py

示例3: charge

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def charge(request):
    cart = Cart(request.session)
    if cart.unique_count > 0:
        if request.method == "POST":
            form = SalePaymentForm(request.POST or None)
            if form.is_valid(): # charges the card
                template = get_template('tinbox/order-response-email.html')
                context = Context({'cart': cart, 'total': cart.total, 'shipping_cost': form.cleaned_data.get("shipping"), 'name' : form.cleaned_data.get("name") })
                content = template.render(context)
                cart.clear()
                form_email = form.cleaned_data.get("email")
                form_name = form.cleaned_data.get("name")
                subject = 'Tinbox Solutions - Order Successfully Processed'
                from_email = settings.EMAIL_HOST_USER
                to_email = [form_email]
                msg = EmailMultiAlternatives(subject, "", from_email, to=to_email)
                msg.attach_alternative(content, "text/html")
                msg.send()
                return HttpResponseRedirect('/shopping/thank-you')
            else:
                t = form.determineShippingFormField(1, cart.total)
                return render_to_response("tinbox/charge.html", RequestContext( request, {'form': form, 'turnaround_cost' : t.turnaround_cost, 'turnaround' : t.turnaround} ) )
        else:
            form = SalePaymentForm()
            t = form.determineShippingFormField(1, cart.total)
        return render_to_response("tinbox/charge.html", RequestContext( request, {'form': form, 'turnaround_cost' : t.turnaround_cost, 'turnaround' : t.turnaround} ) )

    else:
        return render(request, 'tinbox/show-cart.html', {"empty": True})
开发者ID:ehorvat,项目名称:tinbox-webapp,代码行数:31,代码来源:views.py

示例4: add_single

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def add_single(request):
	cart = Cart(request.session)
	plato = Plato.objects.get(id=request.GET.get('product_id'))

	if cart.products:
		if plato.restaurante.id != cart.products[0].restaurante.id:
			cart.clear()		
	cart.add(plato, price=plato.precio)
	return platilla_cesta(request);
开发者ID:gamezinfantes,项目名称:UFood,代码行数:11,代码来源:views.py

示例5: checkout_page

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def checkout_page(request):
    errors = []
    cart = Cart(request.session)
    freight_only = any([item.product.product.freight_only for item in cart.items])
    cost_total = cart.total
    if cart.is_empty:
        return redirect(reverse('store'))
    else:
        if request.POST:
            cart_list = [v for k, v in cart.cart_serializable.items()]
            cal_price = reduce(lambda x, y: x + y, [i['quantity'] * int(i['price']) for i in cart_list])
            delivery = request.POST.get('delivery')
            try:
                shopper = PersonalInfo.objects.get(id=request.user.personalinfo.id)
                if cart.total == cal_price and delivery is not None:
                    order = PurchaseOrder.objects.create(
                        number=0,
                        buyer=shopper,
                        order_time=datetime.now(),
                        freight=0 if cart.total > 1500 else
                        60 if delivery.isdigit() else 90,
                        ship_method='FML' if delivery.isdigit() else 'KTJ',
                        address=delivery,
                        total=cart.total,
                        buyer_notes=request.POST.get('shopper_notes'),
                        order_notes=cart_list
                    )
                    order.number = float(datetime.now().strftime('%y%m%d%H%M%S')) + float(order.id)
                    order.total = order.total + order.freight

                    # 更改為預購模式!
                    for d in cart_list:
                        item = get_object_or_404(Item, id=d['product_pk'])
                        order.sold_goods.add(item)
                        item.pre_order += d['quantity']
                        # print ('id={} / 存貨={} / 售貨={} / 總售貨={}'.format(
                        #     item.id, item.stock,
                        #     item.sold, item.total_sold
                        # ))
                        item.save()
                    order.save()
                    cart.clear()
                    return HttpResponseRedirect(reverse('checkout:orderinfo'))
                else:
                    errors.append('資料有誤 或 尚未填寫,請重新整理再次一次')
            except Exception as e:
                print ('%s (%s)' % (e, type(e)))
    context = {
        'title': '結帳清單',
        'errors': errors,
        'cost_total': cost_total,
        'freight_only': freight_only,
    }
    return render(request, 'checkout/checkout-page.html', context)
开发者ID:YuMingChang,项目名称:MMCB,代码行数:56,代码来源:views.py

示例6: clear_cart

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def clear_cart(request):
    if request.is_ajax():
        cart = Cart(request.session)
        cart.clear()
        return render_to_response('mcat_order/cart.html',
                                   context_instance=RequestContext(request),
                                   content_type="application/xhtml+xml"
                                   )
    else:
        if settings.DEBUG:
            print("Not ajax request")
        raise Http404
开发者ID:synw,项目名称:django-mcat-order,代码行数:14,代码来源:views.py

示例7: dispatch

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
 def dispatch(self, request, *args, **kwargs):
     self.customer = get_object_or_404(Customer, user=self.request.user)
     #~ create the order
     cart = Cart(request.session)
     if cart.count == 0:
         messages.warning(self.request, _(u'The cart is empty: order cancelled'))
         return super(PostOrderView, self).dispatch(request, *args, **kwargs)
     order = Order.objects.create(customer=self.customer, total=cart.total)
     for item in cart.items:
         #~ get the product
         OrderedProduct.objects.create(product=item.product, order=order, quantity=item.quantity, price_per_unit=item.product.price)
     
     cart.clear()
     return super(PostOrderView, self).dispatch(request, *args, **kwargs)
开发者ID:synw,项目名称:django-mcat-order,代码行数:16,代码来源:views.py

示例8: confirmar_pedido

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def confirmar_pedido(request):
    if request.method == 'POST':
        # UF
        uf = Uf.objects.get(sigla=request.POST.get('uf'))
        # Cidade
        cidade = uf.cidade_set.get(nome=request.POST.get('cidade'))
        # Endereço
        endereco = Endereco()
        endereco.logradouro = request.POST.get('logradouro')
        endereco.complemento = request.POST.get('complemento')
        endereco.bairro = request.POST.get('bairro')
        endereco.cep = request.POST.get('cep')
        endereco.cidade = cidade;
        endereco.save()
        # Cliente
        cliente = Cliente()
        cliente.endereco = endereco
        cliente.nome = request.POST.get('nome')
        cliente.telefone = request.POST.get('telefone')
        cliente.email = request.POST.get('email')
        cliente.save()
        # Pedido
        pedido = Pedido()
        pedido.cliente = cliente
        # Carrinho de compras
        carrinho = Cart(request.session)
        pedido.valor_total = carrinho.total
        pedido.save()
        # Item pedido
        for item in carrinho.items:
            print item
            item_pedido = ItemPedido()
            item_pedido.pedido = pedido
            item_pedido.produto = item.product
            item_pedido.quantidade = item.quantity
            item_pedido.preco_unitario = item.price
            item_pedido.preco_total = item.price * item.quantity
            item_pedido.save()
        pedido.save()
        carrinho.clear()
        template = loader.get_template('loja/efetuar-pagamento.html')
        context = RequestContext(request, {'cliente': cliente})
        return HttpResponse(template.render(context))
    else:
        return HttpResponseServerError()
开发者ID:pydawan,项目名称:protetores_bucais,代码行数:47,代码来源:views.py

示例9: checkout

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def checkout(request):
    if request.method == 'POST':
        cart = Cart(request.session)
        order = Order(
            date=timezone.now(),
            customer=request.user,
            total_price=cart.total,
            city=request.POST.get('city'),
            address=request.POST.get('address'),
        )
        order.save()
        for item in cart.items:
            sub_order = SubOrder(
                product=item.product,
                quantity=item.quantity,
                order=order,
            )
            sub_order.save()
        cart.clear()
        return HttpResponse(request)
    return render(request, 'goods/checkout.html')
开发者ID:Spawnvpn,项目名称:web_store,代码行数:23,代码来源:views.py

示例10: order_create

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def order_create(request):
	cart = Cart(request.session)
	if request.method == 'POST':
		form = OrderCreateForm(request.POST)
		if form.is_valid():
			order = form.save(commit=False)
			order.placed_by_user = request.user
			order.save()
			for item in cart.items:
				OrderItem.objects.create(order=order,
											product=item.product,
											price=item.price,
											quantity=item.quantity)
				old_quantity = soap_client.service.findByIsbn(item.product.isbn).quantity
				new_quantity = old_quantity - item.quantity
				soap_client.service.updateQuantity(item.product.isbn, new_quantity)
			cart.clear()
			context={'order': order}	
			return render(request, 'orders/created.html', context)
	else:
		form = OrderCreateForm()
		return render(request, 'orders/create.html', {'cart': cart, 'form': form})	
开发者ID:NickLont,项目名称:bookstore,代码行数:24,代码来源:views.py

示例11: clear

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def clear(request):
	"""
	清空商品
	"""
	cart = Cart(request.session)
	cart.clear()
开发者ID:NirvanaStar,项目名称:woodsam,代码行数:8,代码来源:views.py

示例12: CartTests

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [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

示例13: esvaziar_carrinho

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def esvaziar_carrinho(request):
    carrinho = Cart(request.session)
    carrinho.clear()
    return carrinho_ver(request)
开发者ID:pydawan,项目名称:protetores_bucais,代码行数:6,代码来源:views.py

示例14: clear

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def clear(request):
    cart = Cart(request.session)
    cart.clear()
    return HttpResponseRedirect('/shopping/cart')
开发者ID:ehorvat,项目名称:tinbox-webapp,代码行数:6,代码来源:views.py

示例15: empty

# 需要导入模块: from carton.cart import Cart [as 别名]
# 或者: from carton.cart.Cart import clear [as 别名]
def empty(request):
    cart= Cart(request.session)
    cart.clear()
    return HttpResponseRedirect('/tohfa/')
开发者ID:ritz1302,项目名称:giftwebsite,代码行数:6,代码来源:views.py


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