本文整理汇总了Python中cart.Cart.delete_items方法的典型用法代码示例。如果您正苦于以下问题:Python Cart.delete_items方法的具体用法?Python Cart.delete_items怎么用?Python Cart.delete_items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cart.Cart
的用法示例。
在下文中一共展示了Cart.delete_items方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: order
# 需要导入模块: from cart import Cart [as 别名]
# 或者: from cart.Cart import delete_items [as 别名]
def order(request):
form = OrderForm(request.POST or None, request=request)
if request.method == 'POST':
if form.is_valid():
order = form.save(commit=False)
cart = Cart(request)
item_ct = get_model_content_type(Item)
addon_ct = get_model_content_type(Addon)
for item in cart.cart.item_set.filter(content_type=item_ct):
container = item.product.container
service = container.service
break
order.service = service
order.container = container
order.offline_client = form.save_offline_client()
order.commission = container.owner.commission
order.save()
# generating discount
discount = form.cleaned_data['discount'] or 0
if discount:
discount_transaction = BonusTransaction.objects.create(
client=request.user,
order=order,
amount=str(discount * -1),
is_processed=False,
is_discount=True,
description='discount'
)
if order.client:
order.client.reload_bonus_score(rebuild=True)
order.generate_vote_instance()
# saving items and addons as order relations
# savin items
# for item in cart.cart.item_set.filter(content_type=item_ct):
# order_container = OrderContainer.objects.create(
# content_type=item_ct, object_id=item.product.pk,
# quantity=item.quantity,
# total_price=item.total_price,
# order=order)
#
# savin addons separate inside of items
# for addon in cart.cart.item_set.filter(content_type=addon_ct):
# order_container_item = OrderContainer.objects.get(
# content_type=item_ct,
# object_id=addon.link.pk, order=order)
# order_container = OrderContainer.objects.create(
# parent=order_container_item,
# content_type=addon_ct,
# object_id=addon.product.pk,
# total_price=addon.total_price,
# order=order)
for item in cart:
if isinstance(item.product, Item):
order_container = OrderContainer.objects.create(
content_type=item_ct, object_id=item.product.pk,
quantity=item.quantity,
total_price=item.total_price,
order=order)
# for x in range(item.quantity):
# order.items.add(item.product)
elif isinstance(item.product, Addon):
order_container = OrderContainer.objects.create(
content_type=addon_ct, object_id=item.product.pk,
quantity=item.quantity,
total_price=item.total_price,
order=order)
# for x in range(item.quantity):
# order.addons.add(item.product)
else:
pass
cart.delete_items()
if order.status == 'not_confirmed':
for i in User.objects.filter(is_operator=True):
emails = i.get_emails()
phone = order.container.owner.phone
link = reverse('catalog:service-orders')
async_send_mail(
unicode(_(u"Поступил новый заказ")),
render_to_string(settings.NEW_ORDER_MESSAGE_TEMPLATE_NAME,
{'link': link, 'object': order, 'order_statuses': ORDER_STATUSES,
'site_url': settings.SITE_URL}),
settings.EMAIL_FROM,
emails
)
# message.content_subtype = 'html'
# message.send(fail_silently=True)
if form.cleaned_data['payment_redirect'] == 'online':
order = form.instance
url = order.get_online_payment_url()
return {
'payment_redirect': url,
'order_id': form.instance.pk,
'order_amount': order.cost
}
#.........这里部分代码省略.........