예제 #1
0
def remove(request):
    cart = Cart(request.session)
    event = Event.objects.get(id=request.GET.get('id'))
    cart.remove_single(event)

    messages.success(request, "Event removed from basket")

    return render(request, 'ticket/cart/basket.html')
예제 #2
0
def remove(request):
    cart = Cart(request.session)
    event = Event.objects.get(id=request.GET.get('id'))
    cart.remove_single(event)

    messages.success(request, "Event removed from basket")

    return render(request, 'ticket/cart/basket.html')
예제 #3
0
def remove_single(request):
    cart = Cart(request.session)
    initial_count = cart.count
    product = products[int(request.POST.get('product_id'))]
    cart.remove_single(product)
    after_rmv_count = cart.count
    assert initial_count == after_rmv_count + 1
    return HttpResponse()
예제 #4
0
def remove_single(request):
    cart = Cart(request.session)
    initial_count = cart.count
    product = products[int(request.POST.get('product_id'))]
    cart.remove_single(product)
    after_rmv_count = cart.count
    assert initial_count == after_rmv_count + 1
    return HttpResponse()
예제 #5
0
def remove_from_cart(request, site_id):
    """
    Removes Site from the cart
    """
    cart = Cart(request.session)
    ordered_site = get_object_or_404(OrderSite, pk=site_id)
    cart.remove_single(product=ordered_site)
    message = ("{} have been successfully removed from the cart.".format(
        ordered_site.site.name))
    return JsonResponse({"message": message, "total": cart.total})
예제 #6
0
def remove(request):
	cart = Cart(request.session)
	product_id = request.GET.get('id')
	product = Product.objects.get(id=product_id)
	is_unique = is_product_qty_unique(request, product_id)
	cart.remove_single(product)
	html = new_cart_html(request,0)
	cart_contents_qty = cart_contents_payload_unique(request, is_unique, product_id)
	payload = update_cart_status_and_prepare_payload(request, html, cart_contents_qty, True)
	return HttpResponse(json.dumps(payload), content_type="application/json")
예제 #7
0
def remove_single(request, product_id):
    cart = Cart(request.session)
    if Item2.objects.filter(product_id=product_id):
        product = Item2.objects.get(product_id=product_id)
    elif Item3.objects.filter(product_id=product_id):
        product = Item3.objects.get(product_id=product_id)
    else:
        product = Item4.objects.get(product_id=product_id)
    cart.remove_single(product)
    return HttpResponseRedirect('/tohfa/show')
예제 #8
0
def remove_from_cart(request, slug):
    if request.is_ajax():
        cart = Cart(request.session)
        product = get_object_or_404(Product, slug=slug)
        cart.remove_single(product)
        return render_to_response('mcat_order/cart.html',
                                   context_instance=RequestContext(request),
                                   content_type="application/xhtml+xml"
                                   )
    else:
        if settings.DEBUG:
            print("Not ajax request")
        raise Http404
예제 #9
0
def minus_product(request):
    cart = Cart(request.session)
    menu = get_object_or_404(StoreMenu, pk=request.GET.get('menu'))
    cart.remove_single(menu)
    print(cart.cart_serializable)
    try:
        quantity = cart.cart_serializable[str(menu.pk)]['quantity']
        price = cart.cart_serializable[str(menu.pk)]['price']
    except:
        quantity = 0
        price = 0
    context = {
        'total': cart.total,
        'quantity': quantity,
        'sub_total': int(quantity) * int(price),
    }
    return JsonResponse(context)
예제 #10
0
def remove_single(request):
    cart = Cart(request.session)
    plato = Plato.objects.get(id=request.GET.get('product_id'))
    cart.remove_single(plato)
    return platilla_cesta(request)
예제 #11
0
def remove_single(request):
    cart = Cart(request.session)
    product = Product.objects.get(pk=request.GET.get('id'))
    cart.remove_single(product)
    return redirect('shopping-cart-show')
예제 #12
0
def remove_single(request, id):
    cart = Cart(request.session)
    product = get_object_or_404(models.Product, pk=id)
    cart.remove_single(product)
    return HttpResponse({product.price: 'pr'})
예제 #13
0
파일: views.py 프로젝트: boyxiaolong/shop-1
def remove_single(request, id):
    cart = Cart(request.session)
    product = get_object_or_404(models.Product, pk=id)
    cart.remove_single(product)
    return HttpResponse({product.price:'pr' })
예제 #14
0
def minus(request, product_id):
    cart = Cart(request.session)
    product = Product.objects.get(pk=product_id)
    cart.remove_single(product)
    context = {"cart": cart}
    return render(request, 'shop/show-cart.html', context)
예제 #15
0
def remove_single(request):
    cart = Cart(request.session)
    product = Product.objects.get(pk=request.POST.get('product_id'))
    cart.remove_single(product)
    return HttpResponse()
예제 #16
0
def remove_single(request):
    cart = Cart(request.session)
    product = Product.objects.get(id=request.GET.get('id'))
    if product in cart:
        cart.remove_single(product)
    return redirect('/shopping-cart/show')
예제 #17
0
def remove_single(request, id):
    cart = Cart(request.session)
    product = get_object_or_404(models.Product, pk=id)
    cart.remove_single(product)
    return HttpResponseRedirect('../../../card/showcard')
예제 #18
0
def removeSingle(request):
    cart = Cart(request.session)
    product = Product.objects.get(id=request.GET.get('id'))
    cart.remove_single(product)
    return render(request, 'pagina/mostrar-carrito.html', {'product':product})
예제 #19
0
class CartTests(TestCase):

    def setUp(self):
        engine = import_module(settings.SESSION_ENGINE)
        self.session = engine.SessionStore()
        self.session.save()
        self.client.cookies[settings.SESSION_COOKIE_NAME] = self.session.session_key

        self.factory = RequestFactory()

        self.cart = Cart(self.session)

        self.deer = Product.objects.create(
            name='deer',
            price=10.0,
            custom_id=1,
        )
        self.moose = Product.objects.create(
            name='moose',
            price=20.0,
            custom_id=2,
        )
        self.ticket = Ticket.objects.create(
            name='Clint Mansell',
            price=25.0,
            custom_id=6,
        )

    def show_response(self):
        """
        Utility method to return a response from the `show` view.
        """
        request = self.factory.get(reverse('carton-tests-show'))
        request.session = self.session

        return show(request)

    def test_product_is_added(self):
        """
        Can a product be added to the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.session.save()

        self.assertContains(self.show_response(), '1 deer for $10.0')

    def test_multiple_products_are_added(self):
        """
        Can multiple products be added to the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, '1 deer for $10.0')
        self.assertContains(response, '1 moose for $20.0')

    def test_stale_item_is_removed_from_cart(self):
        """
        Are items which are not in the database kept out of the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, 'deer')
        self.assertContains(response, 'moose')

        self.deer.delete()

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertContains(response, 'moose')

    def test_quantity_increases(self):
        """
        Do multiple calls to `add` increase the quantity in the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.deer, 10.00, 2)
        self.session.save()

        self.assertContains(self.show_response(), '3 deer')

    def test_items_are_counted_properly(self):
        """
        Are items in the cart counted correctly?
        """
        self.cart.add(self.deer, 10.00, 2)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, 'items count: 3')
        self.assertContains(response, 'unique count: 2')

    def test_products_are_removed_all_together(self):
        """
        Can all products of a single type be removed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        self.cart.remove(self.deer)

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertContains(response, 'moose')

    def test_single_product_is_removed(self):
        """
        Can a single instance of a product be removed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.session.save()

        self.cart.remove_single(self.deer)

        self.assertContains(self.show_response(), '2 deer')

    def test_quantity_is_overwritten(self):
        """
        Can an items quantity be changed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.session.save()

        self.cart.set_quantity(self.deer, 4)

        self.assertContains(self.show_response(), '4 deer')

    def test_cart_items_are_cleared(self):
        """
        Can a cart be entirely cleared?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.moose, 20.00, 1)
        self.cart.clear()
        self.session.save()

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertNotContains(response, 'moose')

    @override_settings(CART_PRODUCT_LOOKUP={'price__gt': 1})
    def test_custom_product_filter_are_applied(self):
        """
        We modify the cart queryset to exclude some products. We
        should not be able to add excluded products to the cart.
        """
        exclude = Product.objects.create(
            name='EXCLUDED',
            price=0.99,
            custom_id=100,
        )

        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(exclude, exclude.price, 1)
        self.session.save()

        response = self.show_response()

        self.assertNotContains(response, 'EXCLUDE')
        self.assertContains(response, 'deer')

    def test_get_model_product_path(self):
        """
        Is a string with the full, correct import path returned for a
        model?
        """
        self.assertEqual(
            self.cart.get_product_model_path(self.deer),
            'carton.tests.models.Product',
        )

    def test_different_product_models(self):
        """
        Does the cart work with different models?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.ticket, 25.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, '1 deer for $10.0')
        self.assertContains(response, '1 Clint Mansell for $25.0')
예제 #20
0
    def remove_item(self, request, item_id):
        cart = Cart(session=request.session, session_key=self.session_key)
        product = self.get_product(item_id)
        cart.remove_single(product)

        return redirect(self.redirect_view)
예제 #21
0
class CartTests(TestCase):
    def setUp(self):
        engine = import_module(settings.SESSION_ENGINE)
        self.session = engine.SessionStore()
        self.session.save()
        self.client.cookies[
            settings.SESSION_COOKIE_NAME] = self.session.session_key

        self.factory = RequestFactory()

        self.cart = Cart(self.session)

        self.deer = Product.objects.create(
            name='deer',
            price=10.0,
            custom_id=1,
        )
        self.moose = Product.objects.create(
            name='moose',
            price=20.0,
            custom_id=2,
        )
        self.ticket = Ticket.objects.create(
            name='Clint Mansell',
            price=25.0,
            custom_id=6,
        )

    def show_response(self):
        """
        Utility method to return a response from the `show` view.
        """
        request = self.factory.get(reverse('carton-tests-show'))
        request.session = self.session

        return show(request)

    def test_product_is_added(self):
        """
        Can a product be added to the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.session.save()

        self.assertContains(self.show_response(), '1 deer for $10.0')

    def test_multiple_products_are_added(self):
        """
        Can multiple products be added to the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, '1 deer for $10.0')
        self.assertContains(response, '1 moose for $20.0')

    def test_stale_item_is_removed_from_cart(self):
        """
        Are items which are not in the database kept out of the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, 'deer')
        self.assertContains(response, 'moose')

        self.deer.delete()

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertContains(response, 'moose')

    def test_quantity_increases(self):
        """
        Do multiple calls to `add` increase the quantity in the cart?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.deer, 10.00, 2)
        self.session.save()

        self.assertContains(self.show_response(), '3 deer')

    def test_items_are_counted_properly(self):
        """
        Are items in the cart counted correctly?
        """
        self.cart.add(self.deer, 10.00, 2)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, 'items count: 3')
        self.assertContains(response, 'unique count: 2')

    def test_products_are_removed_all_together(self):
        """
        Can all products of a single type be removed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.cart.add(self.moose, 20.00, 1)
        self.session.save()

        self.cart.remove(self.deer)

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertContains(response, 'moose')

    def test_single_product_is_removed(self):
        """
        Can a single instance of a product be removed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.session.save()

        self.cart.remove_single(self.deer)

        self.assertContains(self.show_response(), '2 deer')

    def test_quantity_is_overwritten(self):
        """
        Can an items quantity be changed?
        """
        self.cart.add(self.deer, 10.00, 3)
        self.session.save()

        self.cart.set_quantity(self.deer, 4)

        self.assertContains(self.show_response(), '4 deer')

    def test_cart_items_are_cleared(self):
        """
        Can a cart be entirely cleared?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.moose, 20.00, 1)
        self.cart.clear()
        self.session.save()

        response = self.show_response()

        self.assertNotContains(response, 'deer')
        self.assertNotContains(response, 'moose')

    @override_settings(CART_PRODUCT_LOOKUP={'price__gt': 1})
    def test_custom_product_filter_are_applied(self):
        """
        We modify the cart queryset to exclude some products. We
        should not be able to add excluded products to the cart.
        """
        exclude = Product.objects.create(
            name='EXCLUDED',
            price=0.99,
            custom_id=100,
        )

        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(exclude, exclude.price, 1)
        self.session.save()

        response = self.show_response()

        self.assertNotContains(response, 'EXCLUDE')
        self.assertContains(response, 'deer')

    def test_get_model_product_path(self):
        """
        Is a string with the full, correct import path returned for a
        model?
        """
        self.assertEqual(
            self.cart.get_product_model_path(self.deer),
            'carton.tests.models.Product',
        )

    def test_different_product_models(self):
        """
        Does the cart work with different models?
        """
        self.cart.add(self.deer, 10.00, 1)
        self.cart.add(self.ticket, 25.00, 1)
        self.session.save()

        response = self.show_response()

        self.assertContains(response, '1 deer for $10.0')
        self.assertContains(response, '1 Clint Mansell for $25.0')
예제 #22
0
def remove_single(request):
	cart = Cart(request.session)
	plato = Plato.objects.get(id=request.GET.get('product_id'))
	cart.remove_single(plato)
	return platilla_cesta(request);