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


Python Cart.delete方法代码示例

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


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

示例1: delete_cart

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete [as 别名]
def delete_cart(request, id):
    cart = Cart(request)
    cart.delete(id)
    if request.META.get('HTTP_X_REQUESTED_WITH', '') == 'XMLHttpRequest':
        return HttpResponse(cart.serialize())
    else:
        return redirect(reverse('show_cart'))
开发者ID:Sergey-L,项目名称:v2,代码行数:9,代码来源:views.py

示例2: test_bug_a_delete

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete [as 别名]
    def test_bug_a_delete(self):
        c = Cart()
        c.delete(0)    
        

    #def test_save_to_session(self):
        #c = Cart((1,1,1))
        #c.save(self.req)
        
        #print self.req.session[settings.CART_SESSSION_NAME]
开发者ID:hnejadi,项目名称:django_tiny_shop,代码行数:12,代码来源:tests.py

示例3: test_cart_test

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete [as 别名]
 def test_cart_test(self):
     c = Cart()
     c.add((1,1,1))
     self.assertEqual(c[0][0], 1)
     c.append((2,2,2))
     self.assertEqual(c[1][0], 2)
     self.assertEqual(c.total(), 2)
     self.assertEqual(c.total_items(), 3)
     c.delete(0)
     self.assertEqual(c.total(), 1)
     self.assertEqual(c[0][0], 2)
     self.assertEqual(c.total_items(), 2)
开发者ID:hnejadi,项目名称:django_tiny_shop,代码行数:14,代码来源:tests.py

示例4: update_cart

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete [as 别名]
def update_cart(request):
    cart = Cart(request)
    product = int(request.POST.get('product', '0'))
    amount = int(request.POST.get('amount', '0'))
    i = int(request.POST.get('i', '0'))
    data = None
    
    if product > 0 and amount >= 0:
        if amount == 0:
            cart.delete(product)
        else:
            cart.update({'product': product, 'amount': amount})
        return HttpResponse(cart.serialize())
    else:
        raise Http404
开发者ID:chukreev-alexey,项目名称:ekaboom,代码行数:17,代码来源:views.py

示例5: cart_list

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete [as 别名]
def cart_list(request, tmpl, action=None, product_id=None):
    cart = Cart(request)
    msg_ok = msg_err = None
    if action == 'del':
        if cart.delete(int(product_id)):
            msg_ok = _(u"Product successfully removed from cart")
        else:
            msg_err = _(u"Error while removing product from cart")
    elif action == 'add' or action == 'update':
        statusok = False
        if len(request.POST)>0:
            statusok = True
            for k,v  in request.POST.iteritems():
                product_id = 0
                try:
                    quantity = int(v)
                except:
                    quantity = 0
                if k.startswith('product_'):
                    product_id = int(k[8:])
                    if action == 'add':
                        statusok = statusok and cart.add(product_id, quantity)
                    else:
                        statusok = statusok and cart.update(product_id, quantity)
                if k == 'donation':
                    statusok = statusok and quantity >= 0
                    if quantity >= 0:
                        cart.donation = quantity
        if statusok:
            msg_ok = _(u"Product(s) successfully added") if action == 'add' else _(u"Product(s) successfully updated")
        else:
            msg_err = _(u"Error while adding product(s)") if action == 'add' else _(u"Error while updating product(s)")
    elif action == 'invalid':
        msg_err = _(u"Unable to confirm your order, one (or more) product(s) in your cart exceed the available quantity")
    elif action == 'uncheckedgcs':
        msg_err = _(u"You have to read and accept the general terms and conditions of sales in order to confirm your order")
    cart.save(request)
    return tmpl, {
        'cart': cart,
        'msg_err': msg_err, 'msg_ok': msg_ok,
        'usegcs': settings.CART_SETTINGS['gcsuse'],
        'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT,
        }
开发者ID:RMLL,项目名称:resarmll,代码行数:45,代码来源:views.py

示例6: del_cart_item

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete [as 别名]
def del_cart_item(request, id):
    cart=Cart(request)
    cart.delete(id)
    return get_cart(request)
开发者ID:chemt,项目名称:vsad,代码行数:6,代码来源:views.py

示例7: manage_cart

# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete [as 别名]
def manage_cart(request, tmpl, user_id=None, action=None, product_id=None):
    user = None
    if user_id:
        try:
            user = User.objects.get(id=user_id)
        except:
            user = None
    msg_ok = msg_err = products = cart = None
    products = None
    if user:
        cart = Cart(request, user.id)
        if request.user.is_staff:
            products = Article.objects.all().order_by('order')
        else:
            products = Article.objects.filter(enabled=True).order_by('order')
        if action == 'add':
            product_id = int(request.POST.get('cart_add'))
            if cart.add(product_id, 1):
                msg_ok = _(u"Product successfully added to cart")
            else:
                msg_err = _(u"Error while adding product to cart")
        elif action == 'del':
            if cart.delete(int(product_id)):
                msg_ok = _(u"Product successfully removed from cart")
            else:
                msg_err = _(u"Error while removing product from cart")
        elif action == 'update':
            update = True
            for k,v  in request.POST.iteritems():
                product_id = 0
                try:
                    quantity = int(v)
                except:
                    quantity = 0
                if k.startswith('product_'):
                    product_id = int(k[8:])
                    update = update and cart.update(product_id, quantity)
            if update:
                msg_ok = _(u"Product(s) successfully updated")
            else:
                msg_err = _(u"Error while updating product(s)")
        elif action == 'validate':
            valid = cart.is_valid()
            if not valid and request.user.is_staff:
                valid = request.POST.get('force') == '1'
            if not valid:
                msg_err = _(u"Unable to confirm this order, one (or more) product(s) in the cart exceed the available quantity")
            else:
                order = Order(user=user, creation_date=date.now())
                order.save_confirm(cart)
                cart.clear()
                msg_ok = _(u"Order successfully confirmed")
        cart.save(request)
    return tmpl, {
        'user_obj': user,
        'products': products,
        'cart': cart,
        'msg_err': msg_err, 'msg_ok': msg_ok,
        'is_admin': request.user.is_staff,
        'currency': settings.CURRENCY, 'currency_alt': settings.CURRENCY_ALT,
    }
开发者ID:RMLL,项目名称:resarmll,代码行数:63,代码来源:views.py


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