本文整理汇总了Python中cart.cart.Cart.add方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.add方法的具体用法?Python Cart.add怎么用?Python Cart.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.cart.Cart
的用法示例。
在下文中一共展示了Cart.add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_project_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def add_project_to_cart(self, request, *args, **kwargs):
project = ProjectPage.objects.get(id=request.POST.get('project_id'))
cart = Cart(request)
cart.add(project, request.POST.get('amount'), 1)
request.session['funder_name']=request.POST.get('name')
request.session['funder_organisation']=request.POST.get('organisation')
return redirect('/order/checkout')
示例2: add_sandwich
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def add_sandwich(request, base):
cart = Cart(request.session)
sand_base = get_object_or_404(Base, pk=base)
form = SandwichForm(request.POST, initial={'base': base})
form2 = QuantityForm(request.POST)
if form.is_valid() and form2.is_valid():
bread = form.cleaned_data['bread']
toppings = form.cleaned_data['toppings']
condiments = form.cleaned_data['condiments']
cheeses = form.cleaned_data['cheeses']
side= form.cleaned_data['side']
quantity = form2.cleaned_data['quantity']
sandwich = Sandwich()
sandwich.base= sand_base
sandwich.bread= bread
sandwich.save()
sandwich.side= side
sandwich.toppings= toppings
sandwich.condiments= condiments
sandwich.cheeses= cheeses
sandwich.save()
product = sandwich
cart.add(product, price=sandwich.price, quantity=quantity)
return HttpResponseRedirect(reverse('cart:show_cart'))
return render(request, 'sandwich_builder/sandwich_constructor.html',
{'base': sand_base, 'form':form})
示例3: add_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [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())
示例4: TestShow
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
class TestShow(TestCase):
def setUp(self):
rf = RequestFactory()
request = rf.get(reverse('cart-show'))
add_session_to_request(request)
self.cart = Cart(request)
product = ProductFactory()
self.cart.add(product, product.price, 1)
self.client = Client()
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
store.save()
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
def test_get(self):
# store cart id in session
session = self.client.session
session['CART-ID'] = self.cart.cart.pk
session.save()
resp = self.client.get(reverse('cart-show'))
self.assertEqual(resp.status_code, 200)
self.assertTemplateUsed(resp, 'check/cart.html')
def test_post(self):
data = {}
for item in self.cart:
data['%s-quantity' % item.product.pk] = 2
# store cart id in session
session = self.client.session
session['CART-ID'] = self.cart.cart.pk
session.save()
resp = self.client.post(reverse('cart-show'), data=data)
self.assertRedirects(resp, reverse('cart-check-in'), status_code=302, target_status_code=200)
示例5: cart_add
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def cart_add(request, product_id):
cart = Cart(request)
product = get_object_or_404(Product, id=product_id)
form = CartAddProductForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
cart.add(product=product, quantity=cd['quantity'],
update_quantity=cd['update'])
return redirect('cart:cart_detail')
示例6: get
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def get(self, request, **kwargs):
if request.is_ajax:
cart = Cart(request)
try:
product = Product.objects.get(id=kwargs['id'])
quantity = 1
cart.add(product, product.price, quantity)
return HttpResponse(json.dumps({'count': cart.count()}))
except:
return HttpResponse(json.dumps({'count': cart.count()}))
示例7: add_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def add_to_cart(request, product_id, quantity):
if int(quantity) > 0:
product = MenuItem.objects.get(id=product_id)
cart = Cart(request)
batch_item = Menu.get_current_menu().itembatch_set.get(item=product)
if batch_item.amount >= int(quantity) + int(cart.get_qty(product)):
cart.add(product, product.retailer_price(request.session['user']), quantity)
request.session['quantity_error'] = None
request.session['quantity_error_item'] = None
return JsonResponse({"return": "ok"})
else:
request.session['quantity_error'] = batch_item.amount
request.session['quantity_error_item'] = product.name
return JsonResponse({"return": "fail"})
示例8: add_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def add_to_cart(request, pk, q):
product = Post.objects.get(id=pk)
product.q = q
cart = Cart(request)
added_product = product
product_user = 0;
if request.user.is_authenticated():
product.q = q
request.user.post_set.add(product)
product_user = request.user.post_set
request.products = request.user.post_set.filter(user=request.user)
else:
cart.add(product, product.price, q)
return redirect('blog.views.get_cart')
示例9: add_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def add_to_cart(request, product_id):
product = get_object_or_404(Product, id=product_id)
cart = Cart(request)
form = CartItemForm(product, request.POST, prefix=str(product.pk))
if form.is_valid():
cd = form.cleaned_data
quantity = cd.get("quantity", "1")
cart.add(product, product.price, int(quantity))
if request.is_ajax():
return JsonResponse({"success": True, "count": cart.cart.item_set.count()})
return redirect("cart-show")
else:
if request.is_ajax():
errors = dict([(k, force_text(v[0])) for k, v in form.errors.items()])
return JsonResponse({"success": False, "errors": errors})
return redirect("cart-show")
示例10: book_detail
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def book_detail(request,slug):
book = get_object_or_404(Book, slug= slug)
categories = Category.objects.filter(is_active=True)
related_books = Book.objects.filter(category=book.category)
#delete oneself from the filter result and get the first four result
related_books = related_books.exclude(id = book.id)[:4]
form = CartAddProductForm()
if request.method == 'POST':
form = CartAddProductForm(request.POST)
'''import pdb; pdb.set_trace()'''
if form.is_valid():
cd = form.cleaned_data
cart = Cart(request)
cart.add( book= book ,quantity = cd['quantity'])
return HttpResponseRedirect(reverse('cart:show_cart'))
else:
return render(request,'catalog/book_detail.html',{'book':book,'related_books':related_books,'categories':categories,'form':form})
示例11: TestCheckIn
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
class TestCheckIn(TestCase):
def setUp(self):
# get request
rf = RequestFactory()
request = rf.get(reverse('cart-check-in'))
add_session_to_request(request)
# get cart
self.cart = Cart(request)
product = ProductFactory()
self.cart.add(product, product.price, 1)
# prepare session
self.client = Client()
engine = import_module(settings.SESSION_ENGINE)
store = engine.SessionStore()
store.save()
self.client.cookies[settings.SESSION_COOKIE_NAME] = store.session_key
def test(self):
data = {
"surname": "Vasiliy",
"name": "Vasya",
"phone": '092-123-45-67',
"email": '[email protected]',
"pay_way": "on_delivery",
"delivery_by": "newpost",
"address": "adress123",
"user_comment": "",
"agree": True,
}
# store cart id in session
session = self.client.session
session['CART-ID'] = self.cart.cart.pk
session.save()
# call check_in
resp = self.client.post(reverse('cart-check-in'), data=data)
# print resp
order = Order.objects.all().reverse()[0]
session['ORDER_PK'] = order.pk
session.save()
# check redirect
self.assertRedirects(resp, reverse('cart-order-preview'), status_code=302, target_status_code=200)
示例12: add_product_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def add_product_to_cart(self, request, *args, **kwargs):
product = ProductPage.objects.get(id=request.POST.get('product_id'))
cart = Cart(request)
cart.add(product, product.prize, request.POST.get('quantity'))
return redirect('/order/checkout')
示例13: add_to_cart
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import add [as 别名]
def add_to_cart(request, cat_id, product_id, quantity):
product = models.Product.objects.get(id=product_id)
cart = Cart(request)
cart.add(product, product.price, quantity)
return redirect('/'+cat_id)