Skip to main content

StandWithUkraine Stand With Ukraine

NOTICE

This frameworks is a fork of another with the same name... Some improvement were made with the target in mind that increase the capabilities of the django-cart

INSTALATION

pip3 install django-new-cart

USAGE

The target of this module is to allow programmers to handle easily the cart of his/her shop web app...

Update urls.py with this url

urlpatterns += [ 
    path("cart/add/<id>/", add, name="cart_add"),
    path("cart/add/<id>/<quantity>/", add_quant, name="cart_add_quantity"),
    path("cart/remove/<id>/", remove, name="cart_remove"),
    path("cart/remove/<id>/<quantity>/", remove_quant, name="cart_remove_quantity"),
    path("cart/clear/", cart_clear, name="cart_clear"),
    path("cart/pop/", cart_pop, name="cart_pop"),
    path("cart/clear/<id>/", item_clear, name="cart_clear_id"),
    path("cart/details/<id>/", cart_detail, name="cart_details"),
    path("cart/update/", update_cart, name="cart_update"),
]

Adding an element

@require_POST
def add(request: HttpRequest, id: int):
    cart = Cart(request)
    cart.add(product=Products.objects.filter(id=id).first())
    return JsonResponse({"result": "ok", 
        "amount": cart.session[CART_SESSION_ID].get(id, {"quantity": 0})["quantity"]
    }

Get details of the cart

@require_POST
def cart_detail(request:HttpRequest, id: int):
    return JsonResponse({"result": Cart(request).get_item(id)})

Cleaning the cart

@require_POST
def cart_clear(request:HttpRequest):
    Cart(request).clear()
    return JsonResponse({"result": "ok", "amount": 0})

Remove all elements of a type from cart

@require_POST
def item_clear(request: HttpRequest, id:int):
    cart = Cart(request)
    cart.remove(product=Products.objects.filter(id=id).first())
    return JsonResponse({
        "result": "ok", 
        "amount": cart.get_sum_of("quantity") 
    })

Removing N elements from cart

@require_POST
def remove_quant(request:HttpRequest, id:int, quantity: int):
    Cart(request).add(product=Products.objects.filter(id=id).first(), quantity=quantity, action="remove")
    return JsonResponse({"result": "ok"})

Remove element

@require_POST
def remove(request:HttpRequest, id: int):
    Cart(request).decrement(product=Products.objects.filter(id=id).first())
    return JsonResponse({"result": "ok"})

Pop last element

@require_POST
def cart_pop(request:HttpRequest,):
    cart = Cart(request)
    cart.pop()
    return JsonResponse({"result": "ok",
        "amount": cart.get_sum_of("quantity")
    })

Adding N elements to cart

@require_POST
def add_quant(request:HttpRequest, id:int, quantity: int):
    cart = Cart(request)
    cart.add(Producsts.objects.filter(id=id).first(), quantity)
    return JsonResponse({"result": "ok", 
        "amount": cart.session[CART_SESSION_ID].get(id, {"quantity": quantity})["quantity"]})

Metadata

Release files for django-new-cart 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-new-cart 1.1.0
File Size Uploaded
django-new-cart-1.1.0.tar.gz 10.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-new-cart 1.1.0
File Interpreter ABI Platform
django_new_cart-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 21.8 kB

Release files / django-new-cart-1.1.0.tar.gz

Download URL django-new-cart-1.1.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9fdfb5111bef903176e56760e02bef270b739b09e73ffe5ee324efd4cbda3ded
BLAKE2b-256 checksum
How to use checksums
9f6918a8472735b0127b80c006761337ab6d995f1cf965887acffb1f33a6c3fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release files / django_new_cart-1.1.0-py3-none-any.whl

Download URL django_new_cart-1.1.0-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63aec75140b5e17434861406171a35c5b13fc3fbb9331904687e0f8addc6cce5
BLAKE2b-256 checksum
How to use checksums
61f38383bca759fb89b28b1aff81f9d23c4cd98b6ba25d3b7df37a89fa4cddaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.10.4

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.3

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page