本文整理汇总了Python中cart.cart.Cart.summary方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.summary方法的具体用法?Python Cart.summary怎么用?Python Cart.summary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.cart.Cart
的用法示例。
在下文中一共展示了Cart.summary方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_from_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def remove_from_cart(request):
product_id = request.POST.get('product_id')[0]
print(product_id)
product = Product.objects.get(pk=product_id)
cart = Cart(request)
cart.remove(product)
return HttpResponse(cart.summary())
示例2: add_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def add_to_cart(request):
product_id = request.POST.get('product_id')[0]
product = Product.objects.get(pk=product_id)
cart = Cart(request)
quantity = 1
cart.add(product, product.price, quantity)
return HttpResponse(cart.summary())
示例3: form_valid
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def form_valid(self, form):
self.object = form.save()
cart = Cart(self.request)
date_order = datetime.now()
order = Order.objects.create(user=self.object,
date_order=date_order,
sum=cart.summary())
for item in cart:
product = get_object_or_404(Product, id=item.product.id)
list_of_order = ListOfOrder.objects.create(order=order,
product=product,
price=item.product.price,
quantity=item.quantity,
sum=item.total_price)
quantity_for_update = product.quantity - item.quantity*50
Product.objects.filter(id=item.product.id).update(quantity=quantity_for_update)
cart.clear()
return redirect(self.get_success_url())
示例4: order
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def order(request):
all_categories = models.Category.objects.all()
cart = Cart(request)
if request.method == 'POST':
user = User.objects.get(username=request.user.username)
new_order = models.Order(user=user)
form = forms.OrderForm(request.POST, instance=new_order)
if form.is_valid():
order = form.save()
email_messages = "您的購物內容如下:\n"
for item in cart:
models.OrderItem.objects.create(order=order,
product=item.product,
price = item.product.price,
quantity=item.quantity)
email_messages = email_messages + "\n" + \
"{}, {}, {}".format(item.product, item.product.price, item.quantity)
email_messages = email_messages + \
"\n以上共計{}元\nhttp://mshop.min-haung.com感謝您的訂購!".format(cart.summary())
messages.add_message(request, messages.INFO, "訂單已儲存,我們會儘快處理。")
send_mail("感謝您的訂購",
email_messages,
'迷你小電商<[email protected]>',
[request.user.email],)
send_mail("有人訂購產品囉",
email_messages,
'迷你小電商<[email protected]>',
['[email protected]'],)
cart.clear()
return redirect('/myorders/')
else:
form = forms.OrderForm()
template = get_template('order.html')
request_context = RequestContext(request)
request_context.push(locals())
html = template.render(request_context)
return HttpResponse(html)
示例5: paypal_pay
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def paypal_pay(request):
"""
Page where we ask user to pay with paypal.
"""
cart = Cart(request)
products = list()
for elem in cart:
products.append(elem.product.name)
paypal_dict = {
"business": "[email protected]",
"amount": cart.summary(),
"currency_code": "RUB",
"item_name": products,
"invoice": "INV-" + str(int(time.time())),
"notify_url": reverse('paypal-ipn'),
"return_url": "http://localhost:8000/payment/success/",
"cancel_return": "http://localhost:8000/payment/cart/",
"custom": str(request.user.id)
}
# Create the instance.
form = PayPalPaymentsForm(initial=paypal_dict)
context = {"form": form, "paypal_dict": paypal_dict}
return render(request, "blog/payment.html", context)
示例6: paypal_success
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def paypal_success(request):
cart = Cart(request)
payment = Payment(payment_type=1, date=datetime.date.today(), cost=cart.summary(), user=request.user)
payment.save()
cart.clear()
return HttpResponse("Money is mine. Thanks.")
示例7: func4
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def func4(request):
cart = Cart(request)
return render(request, 'blog/index4.html', {'cart' : cart, 'total_price' : cart.summary()})
示例8: func2
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def func2(request, product_id):
product = Product.objects.get(pk=product_id)
cart = Cart(request)
return render(request, 'blog/index1.html', {'product': product, 'total_price' : cart.summary()})
示例9: func1
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def func1(request):
cache.get_or_set('items', Product.objects.filter().order_by('name'), 10)
cart = Cart(request)
return render(request, 'blog/index.html', {'items': cache.get_or_set('items', Product.objects.filter().order_by('name'), 10), 'total_price' : cart.summary()})
示例10: assert_total_cart_price
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import summary [as 别名]
def assert_total_cart_price(self, total_price, response):
cart = Cart(self.client)
price = cart.summary()
self.test_case.assertEqual(total_price, price)