本文整理汇总了Python中cart.cart.Cart.clear方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.clear方法的具体用法?Python Cart.clear怎么用?Python Cart.clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.cart.Cart
的用法示例。
在下文中一共展示了Cart.clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
if cart.coupon:
order.coupon = cart.coupon
order.discount = cart.coupon.discount
order.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# Usunięcie zawartości koszyka na zakupy.
cart.clear()
# Uruchomienie zadania asynchronicznego.
order_created.delay(order.id) # Umieszczenie zamówienia w sesji.
request.session['order_id'] = order.id # Przekierowanie do płatności.
return redirect(reverse('payment:process'))
else:
form = OrderCreateForm()
return render(request,
'orders/order/create.html',
{'cart': cart, 'form': form})
示例2: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save()
for item in cart:
OrderItem.objects.create(
order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity']
)
# clear the cart
cart.clear()
# launch asynchronous task
order_created.delay(order.id)
return render(
request,
'orders/order/created.html',
{'order': order}
)
else:
form = OrderCreateForm()
return render(
request,
'orders/order/create.html',
{
'cart': cart,
'form': form
}
)
示例3: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
if cart.coupon:
order.coupon = cart.coupon
order.discount = cart.coupon.discount
order.save()
try:
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
qty=item['qty'])
except Exception as exp:
return HttpResponseBadRequest(str(exp))
# clear the cart
cart.clear()
# send email asynchronously
order_created.delay(order.id)
# set the order in the session
request.session['order_id'] = order.id
# redirect for payment
return redirect(reverse('payment:process'))
else:
form = OrderCreateForm()
return render(request,
'orders/order/create.html',
{'form': form, 'cart': cart})
示例4: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
user = request.user
if request.method == 'POST':
form= OrderForm(user,request.POST)
order = form.save(commit = False)
order.user = user
order.save()
for item in cart:
OrderItem.objects.create(order= order, book = item.book , quantity= item.quantity)
cart.clear()
return redirect('order:order_detail', order_id = order.order_id)
else:
form = OrderForm(user)
categories =[]
for item in cart:
category = item.book.category
if category not in categories:
categories.append(category)
if categories:
related_books = Book.objects.filter(category = categories[0])
if len(categories)>1:
for category in categories[1:]:
related_books= related_books|(Book.objects.filter(category = category))
related_books = related_books[:5]
return render(request,'order/order_form.html',{'cart':cart, 'form':form,'related_books':related_books})
示例5: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# clear the cart
cart.clear()
#levantar una excepcion si cart esta vacío para informar que
#no hay productos seleccionados o ya fue generada una orden
# launch asynchronous task
#order_created.delay(order.id)
order_created(order.id)
request.session['order_id'] = order.id
return redirect(reverse('payment:process'))
else:
form = OrderCreateForm()
return render(request,
'orders/order/create.html',
{'cart': cart, 'form': form})
示例6: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
if cart.coupon:
order.coupon = cart.coupon
order.discount = cart.coupon.discount
order.save()
products_for_redis=[]
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
products_for_redis.append(item['product'])
# clear the cart
r=Recommender()
r.products_bought(products_for_redis)
cart.clear()
# launch asynchronous task
current_lang=translation.get_language()
order_created.delay( order.id, current_lang)
return render(request,
'orders/order/created.html',
{'order': order})
else:
form = OrderCreateForm()
return render(request,
'orders/order/create.html',
{'cart': cart, 'form': form})
示例7: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
order.account_id = request.user
order.first_name = request.user.first_name
order.last_name = request.user.last_name
order.address = request.user.profile.address
order.phone = request.user.profile.cellphone
order.shipment_cost = cart.get_shipment_cost()
order.books_cost = cart.get_book_price()
order.save()
for item in cart:
OrderList.objects.create(order_id=order,
book_id=item['book'],
book_quantity=item['quantity'],
price=item['price'],
discount=item['discount'])
cart.clear()
order_created(request, order.id)
request.session['order_id'] = order.id
messages.success(request,
'Your order was successfully placed!Please Check your email!')
return redirect('IB:book_list')
else:
messages.error(request, 'Your order got somthing wrong!')
else:
form = OrderCreateForm()
return render(request,
'createOrder.html',
{'cart': cart,
'form': form})
示例8: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
if cart.coupon:
order.coupon = cart.coupon
order.discount = cart.coupon.discount
order.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# clear the cart
cart.clear()
# launch asynchronous task
order_created.delay(order.id)
# set the order in the session
request.session['order_id'] = order.id
# redirect to the payment
return redirect(reverse('payment:process'))
else:
form = OrderCreateForm()
return render(request, 'orders/order/create.html', {'cart': cart,
'form': form})
示例9: post
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def post(self,request):
cart=Cart(request)
form=OrderCreateForm(request.POST)
if form.is_valid():
order=form.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# Borrar el carrito
cart.clear()
# Lanzamos la tarea asincrona
# order_created.delay(order.id)
# Mandamos email sin tarea asincrona
# seteamos la orden en la sesion para paypal
request.session['order_id']=order.id
# redireccionamos hacia el cobro
return redirect(reverse('payment:process'))
# template='orders/order/created.html'
# context={
# 'order':order
# }
# return render(request,template,context)
else:
cart=Cart(request)
form=OrderCreateForm(request.POST)
template='orders/order/create.html'
context={
'cart':cart,
'form':form
}
return render(request,template,context)
示例10: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrdenCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
if cart.coupon:
order.coupon = cart.coupon
order.discount = cart.coupon.discount
order.save()
for item in cart:
OrderItem.objects.create(
orden=order,
product=item['product'],
precio=item['price'],
cantidad=item['quantity'],
)
#limpiamos l carro
cart.clear()
#lanzamos el proceso asincrono
order_created.delay(order.id)
#set the order in the session
request.session['order_id'] = order.id
#redirect to the payment
return redirect(reverse('payment:process'))
else:
form = OrdenCreateForm()
return render(request, 'orders/order/created.html', {'cart':cart, 'form':form})
示例11: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
order = form.save(commit=False)
if cart.coupon:
order.coupon = cart.coupon
order.discount = cart.coupon.discount
order.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# clear the cart
cart.clear()
# launch asynchronous task
order_created.delay(order.id)
# set the order in the session
request.session['order_id'] = order.id
# Increment the score of each product id contained in the order.
# The score represents the times another product has been bought
# together with the given product.
Recommender().products_bought(item['product'] for item in cart)
# redirect ot the payment
return redirect(reverse('payment:process'))
else:
form = OrderCreateForm()
return render(request,
'orders/order/create.html',
{'cart': cart, 'form': form})
示例12: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
'''get the product in cart of session and generate an order'''
cart=Cart(request) #get the cart information as a dictionary
if request.method=='POST':
form=OrderCreateForm(request.POST) #get the user input information
if form.is_valid():
order=form.save() #save the input information into database
for item in cart: #save the products in cart into database
OrderItem.objects.create(order=order,product=item['product'],price=item['price'],quantity=item['quantity'])
# Clear the cart information in session
cart.clear()
# Launch asynchronous task
# Call delay() method of hte task to execute it asynchronously. The task will be added to the queue and will be executed by a worker as soon as possible.
order_created.delay(order.id)
#set the order in the session
request.session['order_id']=order.id
#return render(request, 'orders/order/created.html',{'order':order})
#redirect to the payment
return redirect(reverse('payment:process'))
else:
form=OrderCreateForm()
return render(request, 'orders/order/create.html',{'cart':cart,'form':form})
示例13: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request):
cart = Cart(request)
if request.method == 'POST':
form = OrderCreateForm(request.POST)
if form.is_valid():
#order = form.save()
order = form.save(commit=False)
if cart.coupon:
order.coupon = cart.coupon
order.discount = cart.coupon.discount
order.save()
for item in cart:
OrderItem.objects.create(order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'])
# clear the cart
cart.clear()
# launch task
order_created(order.id)
return render(request, 'shop/orders/created.html', {'order': order})
else:
form = OrderCreateForm()
return render(request, 'shop/orders/create.html', {'cart': cart,
'form': form})
示例14: order_create
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def order_create(request,total=None):
cart = Cart(request)
if request.method == 'POST':
if request.POST.get('deliver_btn') is not None:
addid=request.POST.get('optradio')
addresses=Address.objects.filter(id=addid)
for address in addresses:
form = OrderCreateForm(request.POST)
if form.is_valid():
form.save()
order = form.save()
order.user_id=request.user.id
order.fullname=address.fullname
order.mobile=address.mobile
order.town=address.town
order.pincode=address.pincode
order.state=address.state
order.house=address.house
order.area=address.area
order.landmark=address.landmark
order.save()
tot=0
for item in cart:
if item['product'].stock != 0 :
OrderItem.objects.create(
order=order,
product=item['product'],
price=item['price'],
quantity=item['quantity'],
user_id=request.user.id,
)
tot=tot+item['price']
old_stock=Product.objects.filter(id=item['product'].id)
quantity=item['quantity']
for old in old_stock:
new_stock=int(old.stock)-int(quantity)
old.stock=new_stock
old.save()
print(tot)
cart.clear()
request.session['order_id']=order.id
request.session['total']=int(tot)*int(100)
us=User.objects.filter(id=request.user.id)
for u in us:
request.session['mail']=u.email
return redirect('orders:homeview')
# return render(request, 'orders/order/created.html',{'order':order})
else:
form = OrderCreateForm()
addresses=Address.objects.filter(user_id=request.user.id)
context={
'form': form,
'addresses':addresses,
'total':total
}
return render(request, 'orders/order/create.html',context)
示例15: form_valid
# 需要导入模块: from cart.cart import Cart [as 别名]
# 或者: from cart.cart.Cart import clear [as 别名]
def form_valid(self, form):
self.order = form.save()
cart = Cart(self.request)
for item in cart:
OrderItem.objects.create(order=self.order, product=item['product'], price=item['price'],
quantity=item['quantity'])
cart.clear()
# launch asynchronous task, only work if worker is running
order_created.delay(self.order.id) # set the order in the session
# return render(self.request, 'orders/order/created.html', {'order': self.order})
# redirect to the payment (paypal)
self.request.session['order_id'] = self.order.id
return redirect(reverse('payment:process'))