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


Python Cart.clear方法代码示例

本文整理汇总了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})
开发者ID:gorczynski,项目名称:django-by-example,代码行数:29,代码来源:views.py

示例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
        }
    )
开发者ID:mazulo,项目名称:myshop,代码行数:34,代码来源:views.py

示例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})
开发者ID:amanprodigy,项目名称:samplerepo,代码行数:34,代码来源:views.py

示例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})
开发者ID:zshuangyan,项目名称:syan,代码行数:28,代码来源:views.py

示例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})
开发者ID:GonzaloAvilez,项目名称:kaay,代码行数:30,代码来源:views.py

示例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})
开发者ID:lubart2517,项目名称:shop,代码行数:34,代码来源:views.py

示例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})
开发者ID:InternetBookstore,项目名称:InternetBookstore,代码行数:36,代码来源:views.py

示例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})
开发者ID:Shamiltons,项目名称:python-revision,代码行数:29,代码来源:views.py

示例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)
开发者ID:HectorBlisS,项目名称:namuh,代码行数:35,代码来源:views.py

示例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})
开发者ID:solidfounds,项目名称:emcom-xntk,代码行数:31,代码来源:views.py

示例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})
开发者ID:boreyko,项目名称:django_ahead,代码行数:34,代码来源:views.py

示例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})
开发者ID:extremewaysback,项目名称:origin,代码行数:27,代码来源:views.py

示例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})
开发者ID:janusnic,项目名称:dj-21v,代码行数:27,代码来源:views.py

示例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)
开发者ID:adityasam1994,项目名称:website,代码行数:60,代码来源:views.py

示例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'))
开发者ID:oiacrasec,项目名称:Ecommerce,代码行数:18,代码来源:views.py


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