本文整理汇总了Python中cart.Cart.items方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.items方法的具体用法?Python Cart.items怎么用?Python Cart.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.Cart
的用法示例。
在下文中一共展示了Cart.items方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkout
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import items [as 别名]
def checkout(request):
if request.method == 'POST':
cart = Cart(request)
form = CheckoutForm(request.POST)
if form.is_valid():
try:
if 'email' in request.POST:
update_email(request.user, request.POST.get('email'))
customer = get_customer(request.user)
customer.update_card(request.POST.get("stripeToken"))
product = cart.items()[0].product
customer.subscribe(product.plan)
cart.clear()
return redirect("order_confirmation")
except stripe.StripeError as e:
try:
error = e.args[0]
except IndexError:
error = "unknown error"
return render_to_response('godjango_cart/checkout.html', {
'cart': Cart(request),
'publishable_key': settings.STRIPE_PUBLIC_KEY,
'error': error
},
context_instance=RequestContext(request))
else:
return render_to_response('godjango_cart/checkout.html', {
'cart': Cart(request),
'publishable_key': settings.STRIPE_PUBLIC_KEY,
'error': "Problem with your card please try again"
},
context_instance=RequestContext(request))
else:
return render_to_response('godjango_cart/checkout.html', {
'cart': Cart(request),
'publishable_key': settings.STRIPE_PUBLIC_KEY
},
context_instance=RequestContext(request))
示例2: remove_item_from_cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import items [as 别名]
def remove_item_from_cart(request):
if request.method == "POST" and request.is_ajax:
print request.POST
##todo 404 if cant find
cart = Cart(request)
item = cart.get_item_by_id(request.POST["id"])
cart.remove(item.product)
data = {"cartcount": len(cart.items()),
"id": request.POST["id"] }
json = simplejson.dumps(data)
return HttpResponse(json, mimetype='application/json')
else:
return HttpResponseServerError("GET petitions are not allowed for this view.")
示例3: add_item_to_cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import items [as 别名]
def add_item_to_cart(request):
if request.method == "POST" and request.is_ajax:
print request.POST
##todo 404 if cant find
img = GalleryImage.objects.get(name=request.POST['name'])
#print str(img)
printsize = PrintSize.objects.get(print_size=request.POST['size'])
#print printsize
cart = Cart(request)
cart.add(product=img, unit_price=printsize.price, description= printsize.print_size + " Print", quantity=1)
data = {"cartcount": len(cart.items()) }
json = simplejson.dumps(data)
return HttpResponse(json, mimetype='application/json')
else:
return HttpResponseServerError("GET petitions are not allowed for this view.")