本文整理汇总了Python中cart.Cart.add方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.add方法的具体用法?Python Cart.add怎么用?Python Cart.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.Cart
的用法示例。
在下文中一共展示了Cart.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_item_to_cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def add_item_to_cart(request, item_pk, quantity=1, checkout=False):
cart = Cart(request)
item = get_object_or_404(Item, pk=item_pk)
# checking input data, validate it and raise error if something
# goes unusual, without any data post for time measure resons
threshold = item.category.threshold
try:
quantity = int(quantity)
except TypeError:
raise Http404("Go fsck yourself")
if int(quantity) < threshold:
msg = _("You can not order less of item quantity then "
"given threshold"
)
return {'success': False, 'errors': unicode(msg)}
if int(quantity) % threshold != 0:
msg = _(
"Quantity should be proportional to its item category threshold, "
"you can not add items without it"
)
return {'success': False, 'errors': unicode(msg)}
ct = ContentType.objects.get(
app_label=Item._meta.app_label,
model=Item._meta.module_name)
try:
cart.add(item, item.get_cost(), quantity)
except ItemAlreadyExists:
cart_item = cart.cart.item_set.get(object_id=item_pk, content_type=ct)
if checkout:
cart_item.quantity = quantity
else:
cart_item.quantity += quantity
cart_item.save()
return {'redirect': 'catalog:cart'}
return {'redirect': request.META.get('HTTP_REFERER', '/')}
示例2: test_email_change_while_checkingout
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def test_email_change_while_checkingout(self, UpdateMock, SubscribeMock, ChargeMock):
Customer.objects.create(
user=self.user,
stripe_id=1
)
request = self.factory.post(
'/cart/checkout/',
{
'stripeToken':'xxxxxxxxxx',
'email': '[email protected]'
}
)
request.user = self.user
request.session = {}
cart = TheCart(request)
sub = Subscription.objects.get(plan='monthly')
cart.add(sub, sub.price, 1)
self.assertEqual(request.user.email, '[email protected]')
response = views.checkout(request)
self.assertEqual(response.status_code, 302)
user = User.objects.get(pk=1)
self.assertEqual(request.user.email, '[email protected]')
示例3: test_add_with_quantity_to_existing_item
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def test_add_with_quantity_to_existing_item(self):
'''Adding an item with a quantity increases the quantity of an
existing item.'''
cart = Cart()
cart.add('apple', 2)
cart.add('apple', 3)
self.assertEqual(cart.get_item('apple').quantity, 5)
示例4: test_successful_purchase_with_coupon
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def test_successful_purchase_with_coupon(self):
customer = mommy.make('payments.Customer')
self.request.POST.update({'coupon': 'allthethings'})
form = CheckoutForm(self.request.POST)
self.assertTrue(form.is_valid())
subscription = mommy.make('godjango_cart.Subscription', plan="monthly")
cart = TheCart(self.request)
cart.add(subscription, 9.00, 1)
self.mock.StubOutWithMock(self.view, 'get_form_kwargs')
self.mock.StubOutWithMock(views.CartMixin, 'get_cart')
self.mock.StubOutWithMock(views.CustomerMixin, 'get_customer')
self.mock.StubOutWithMock(customer, 'can_charge')
self.mock.StubOutWithMock(customer, 'subscribe')
self.view.get_form_kwargs().AndReturn(
{'data': {'coupon': 'allthethings'}})
views.CartMixin.get_cart().AndReturn(cart)
views.CustomerMixin.get_customer().AndReturn(customer)
customer.can_charge().AndReturn(True)
customer.subscribe('monthly', coupon='allthethings')
self.mock.ReplayAll()
response = self.view.form_valid(form)
self.mock.VerifyAll()
self.assertEqual(response.status_code, 302)
示例5: add_to_cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def add_to_cart(request, product_id, quantity):
product = Product.objects.get(id=product_id)
cart = Cart(request)
#print("Cart made")
#print(request.session[CART_ID])
#data = {'product': product}
cart.add(product, product.price, quantity)
示例6: subscribe
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def subscribe(request):
cart = Cart(request)
if cart.count() < 1:
sub = Subscription.objects.get(plan="monthly")
cart.add(sub, sub.price, 1)
return redirect("checkout")
示例7: add_to_cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def add_to_cart(request):
print "add to cart\n"
product = Product.objects.get(id=request.POST["product_id"])
cart = Cart(request)
cart.add(product)
request.basket_number = cart.getItemCount()
return render_to_response('basket.html', dict(cart=cart, total_price=cart.getTotalPrice(), products=Product.objects.all()), context_instance=RequestContext(request))
示例8: test_add_two_same_item
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def test_add_two_same_item(self):
'''Adding more than one of the same item does not create duplicate
CartItems.'''
cart = Cart()
cart.add('apple')
cart.add('apple')
self.assertEqual(len(cart), 1)
示例9: add_to_cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def add_to_cart(request):
quantity = 1
supply_id = request.GET.get('id', None)
if (supply_id):
user_id = "anon"
if request.user.id:
user_id = request.user.id
supply = Supply.objects.get(id=supply_id)
cart = Cart(request)
cart.add(supply, supply.price, quantity)
analytics.track(user_id, 'Added to cart', {
'supply_id' : supply.id,
"supply_name" : supply.name
})
if request.session.get('email', '') == '':
return redirect('cart.views.get_email')
return redirect('cart.views.view_cart')
示例10: test_get_total_multiple_items_multiple_quantity
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def test_get_total_multiple_items_multiple_quantity(self):
'''Correct total for multiple items with multiple quantities in
cart.'''
cart = Cart(self._create_product_store())
cart.add('apple', 2)
cart.add('strawberries', 3)
self.assertEqual(cart.get_total(), Decimal('6.30'))
示例11: order_repeat
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def order_repeat(request, pk):
order = get_object_or_404(Order, pk=pk)
containers = order.order_container_order_set.all()
cart = Cart(request)
if cart.cart.item_set.count() != 0:
messages.error(
request, _("You can not repeat order if there's something "
"in the cart, please cleanse it")
)
# return redirect(request.META.get('HTTP_REFERER', '/'))
return redirect(reverse('catalog:service-page',
args=(order.container.owner.pk,)))
for container in containers:
model_class = container.content_type.model_class()
item = get_object_or_None(
model_class.whole_objects, pk=container.object_id
)
if item.is_deleted:
messages.warning(
request, _("Item '%s' does not exist anymore, sorry") % \
item.title
)
else:
cart.add(item, item.get_cost(), container.quantity)
# return redirect(request.META.get('HTTP_REFERER', '/'))
return redirect(reverse('catalog:service-page',
args=(order.container.owner.pk,)))
示例12: add_to_cart
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def add_to_cart(request):
id = ClientJob.objects.aggregate(Max('job_no'))
maxid =id['job_no__max']
product = TestTotal.objects.get(job_no=maxid)
#unit = TestTotal.objects.values_list('unit_price',flat=True).filter(job_no=maxid)
#unit_price = unit
cart = Cart(request)
cart.add(product, product.unit_price)
示例13: test_get_item
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def test_get_item(self):
'''cart.get_item() returns expected CartItem.'''
cart = Cart()
cart.add('apple')
cart.add('orange')
returned_cart_item = cart.get_item('apple')
self.assertTrue(type(returned_cart_item) is CartItem)
self.assertEqual(returned_cart_item.product, 'apple')
示例14: add
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def add(request):
if(request.is_ajax() and request.POST):
video = get_object_or_404(Video, pk=request.POST['video_pk'])
cart = Cart(request)
cart.add(video, video.price, 1)
return HttpResponse("{'success':true}", mimetype="application/json")
else:
raise Http404
示例15: test_add_two_same_item_increases_quantity
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import add [as 别名]
def test_add_two_same_item_increases_quantity(self):
'''Adding an item that is already in the cart increases its
quantity.'''
cart = Cart()
cart.add('apple')
cart.add('apple')
cartitem = cart.get_item('apple')
self.assertEqual(cartitem.quantity, 2)