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


Python Cart.items方法代码示例

本文整理汇总了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))
开发者ID:destos,项目名称:godjango-site,代码行数:47,代码来源:views.py

示例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.")
开发者ID:dnelsonwsu,项目名称:ayatakshiart,代码行数:22,代码来源:views.py

示例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.")
开发者ID:dnelsonwsu,项目名称:ayatakshiart,代码行数:23,代码来源:views.py


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