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


Python cart.Cart类代码示例

本文整理汇总了Python中cart.cart.Cart的典型用法代码示例。如果您正苦于以下问题:Python Cart类的具体用法?Python Cart怎么用?Python Cart使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Cart类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: order_create

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,代码行数:27,代码来源:views.py

示例2: TestShow

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)
开发者ID:pombredanne,项目名称:minishop,代码行数:34,代码来源:test_views.py

示例3: order_create

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,代码行数:27,代码来源:views.py

示例4: add_sandwich

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

示例5: order_create

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,代码行数:32,代码来源:views.py

示例6: order_create

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,代码行数:32,代码来源:views.py

示例7: order_create

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,代码行数:25,代码来源:views.py

示例8: order_create

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,代码行数:32,代码来源:views.py

示例9: remove_from_cart

def remove_from_cart(request):
    product_id = request.POST.get('product_id')[0]
    print(product_id)
    product = Product.objects.get(pk=product_id)
    cart = Cart(request)
    cart.remove(product)
    return HttpResponse(cart.summary())
开发者ID:Lokorus,项目名称:online_store,代码行数:7,代码来源:views.py

示例10: order_create

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,代码行数:25,代码来源:views.py

示例11: add_to_cart

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())
开发者ID:Lokorus,项目名称:online_store,代码行数:7,代码来源:views.py

示例12: create_order

 def create_order(self, client):
     cart = Cart(self.client)
     cart.create_cart()
     cart = cart.cart
     order = Order(client=client, cart=cart)
     order.save()
     return order
开发者ID:cuescience,项目名称:cuescience-shop,代码行数:7,代码来源:support.py

示例13: add_project_to_cart

 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')
开发者ID:acidjunk,项目名称:funder,代码行数:7,代码来源:order.py

示例14: order_create

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,代码行数:29,代码来源:views.py

示例15: post

	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,代码行数:33,代码来源:views.py


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