{ "info": { "author": "jgouveia", "author_email": "studyclassoficial@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable" ], "description": "Django Carton\r\n=============\r\n\r\n\r\n +------+\r\n /| /|\r\n +-+----+ | django-carton is a simple and lightweight application\r\n | | | | for shopping carts and wish lists.\r\n | +----+-+\r\n |/ |/\r\n +------+\r\n\r\n\r\n\r\n* Simple: You decide how to implement the views, templates and payment\r\n processing.\r\n* Lightweight: The cart lives in the session.\r\n* Just a container: You define your product model the way you want.\r\n\r\n\r\nUsage Example\r\n-------------\r\n\r\nView:\r\n\r\n from django.http import HttpResponse\r\n\r\n from carton.cart import Cart\r\n from products.models import Product\r\n\r\n def add(request):\r\n cart = Cart(request.session)\r\n product = Product.objects.get(id=request.GET.get('product_id'))\r\n cart.add(product, price=product.price)\r\n return HttpResponse(\"Added\")\r\n\r\n def show(request):\r\n return render(request, 'shopping/show-cart.html')\r\n\r\n\r\nWe are assuming here that your products are defined in an application\r\ncalled ``products``.\r\n\r\nTemplate:\r\n\r\n {% load carton_tags %}\r\n {% get_cart as cart %}\r\n\r\n {% for item in cart.items %}\r\n {{ item.product.name }}\r\n {{ item.quantity }}\r\n {{ item.subtotal }}\r\n {% endfor %}\r\n\r\n You can also use this convinent shortcut:\r\n {% for product in cart.products %}\r\n {{ product.name }}\r\n {% endfor %}\r\n\r\nWithin the template you can access the product id with {{product.id}}.\r\n\r\nSettings:\r\n\r\n CART_PRODUCT_MODEL = 'products.models.Product'\r\n\r\n\r\nThis project is shipped with an application example called ``shopping``\r\nimplementing basic add, remove, display features.\r\nTo use it, you will need to install the ``shopping`` application and\r\ninclude the URLs in your project ``urls.py``\r\n\r\n # settings.py\r\n INSTALLED_APPS = (\r\n 'carton',\r\n 'shopping',\r\n 'products',\r\n )\r\n\r\n # urls.py\r\n urlpatterns = patterns('',\r\n url(r'^shopping-cart/', include('shopping.urls')),\r\n )\r\n\r\n\r\nAssuming you have some products defined, you should be able to\r\nadd, show and remove products like this:\r\n\r\n /shopping-cart/add/?id=1\r\n /shopping-cart/show/\r\n /shopping-cart/remove/?id=1\r\n\r\n\r\nInstallation\r\n------------\r\n\r\nThis application requires Django version 1.4; all versions above should be fine.\r\n\r\nJust install the package using something like pip and add ``carton`` to\r\nyour ``INSTALLED_APPS`` setting.\r\n\r\nAdd the `CART_PRODUCT_MODEL` setting, a dotted path to your product model.\r\n\r\nThis is how you run tests:\r\n\r\n ./manage.py test carton.tests --settings=carton.tests.settings\r\n\r\n\r\nAbstract\r\n--------\r\n\r\nThe cart is an object that's stored in session. Products are associated\r\nto cart items.\r\n\r\n Cart\r\n |-- CartItem\r\n |----- product\r\n |----- price\r\n |----- quantity\r\n\r\nA cart item stores a price, a quantity and an arbitrary instance of\r\na product model.\r\n\r\n\r\nYou can access all your product's attributes, for instance it's name:\r\n\r\n {% for item in cart.items %}\r\n {{ item.price }}\r\n {{ item.quantity }}\r\n {{ item.product.name }}\r\n {% endfor %}\r\n\r\n\r\n\r\nManaging Cart Items\r\n-------------------\r\n\r\nThese are simple operations to add, remove and access cart items:\r\n\r\n >>> apple = Product.objects.all()[0]\r\n >>> cart.add(apple, price=1.5)\r\n >>> apple in cart\r\n True\r\n >>> cart.remove(apple)\r\n >>> apple in cart\r\n False\r\n\r\n >>> orange = Product.objects.all()[1]\r\n >>> cart.add(apple, price=1.5)\r\n >>> cart.total\r\n Decimal('1.5')\r\n >>> cart.add(orange, price=2.0)\r\n >>> cart.total\r\n Decimal('3.5')\r\n\r\nNote how we check weather the product is in the cart - The following\r\nstatements are different ways to do the same thing:\r\n\r\n >>> apple in cart\r\n >>> apple in cart.products\r\n >>> apple in [item.product for item in cart.items]\r\n\r\n\r\nThe \"product\" refers to the database object. The \"cart item\" is where\r\nwe store a copy of the product, it's quantity and it's price.\r\n\r\n >>> cart.items\r\n [CartItem Object (apple), CartItem Object (orange)]\r\n\r\n >>> cart.products\r\n [, ]\r\n\r\n\r\nClear all items:\r\n\r\n >>> cart.clear()\r\n >>> cart.total\r\n 0\r\n\r\n\r\nIncrease the quantity by adding more products:\r\n\r\n >>> cart.add(apple, price=1.5)\r\n >>> cart.add(apple) # no need to repeat the price.\r\n >>> cart.total\r\n Decimal('3.0')\r\n\r\n\r\nNote that the price is only needed when you add a product for the first time.\r\n\r\n >>> cart.add(orange)\r\n *** ValueError: Missing price when adding a cart item.\r\n\r\n\r\nYou can tell how many items are in your cart:\r\n\r\n >>> cart.clear()\r\n >>> cart.add(apple, price=1.5)\r\n >>> cart.add(orange, price=2.0, quantity=3)\r\n >>> cart.count\r\n 4\r\n >>> cart.unique_count # Regarless of product's quantity\r\n 2\r\n\r\n\r\nYou can add several products at the same time:\r\n\r\n >>> cart.clear()\r\n >>> cart.add(orange, price=2.0, quantity=3)\r\n >>> cart.total\r\n Decimal('6')\r\n >>> cart.add(orange, quantity=2)\r\n >>> cart.total\r\n Decimal('10')\r\n\r\n\r\nThe price is relevant only the first time you add a product:\r\n\r\n >>> cart.clear()\r\n >>> cart.add(orange, price=2.0)\r\n >>> cart.total\r\n Decimal('2')\r\n >>> cart.add(orange, price=100) # this price is ignored\r\n >>> cart.total\r\n Decimal('4')\r\n\r\n\r\nNote how the price is ignored on the second call.\r\n\r\n\r\nYou can change the quantity of product that are already in the cart:\r\n\r\n >>> cart.add(orange, price=2.0)\r\n >>> cart.total\r\n Decimal('2')\r\n >>> cart.set_quantity(orange, quantity=3)\r\n >>> cart.total\r\n Decimal('6')\r\n >>> cart.set_quantity(orange, quantity=1)\r\n >>> cart.total\r\n Decimal('2')\r\n >>> cart.set_quantity(orange, quantity=0)\r\n >>> cart.total\r\n 0\r\n >>> cart.set_quantity(orange, quantity=-1)\r\n *** ValueError: Quantity must be positive when updating cart\r\n\r\n\r\n\r\nRemoving all occurrence of a product:\r\n\r\n >>> cart.add(apple, price=1.5, quantity=4)\r\n >>> cart.total\r\n Decimal('6.0')\r\n >>> cart.remove(apple)\r\n >>> cart.total\r\n 0\r\n >>> apple in cart\r\n False\r\n\r\n\r\nRemove a single occurrence of a product:\r\n\r\n >>> cart.add(apple, price=1.5, quantity=4)\r\n >>> cart.remove_single(apple)\r\n >>> apple in cart\r\n True\r\n >>> cart.total\r\n Decimal('4.5')\r\n >>> cart.remove_single(apple)\r\n >>> cart.total\r\n Decimal('3.0')\r\n >>> cart.remove_single(apple)\r\n >>> cart.total\r\n Decimal('1.5')\r\n >>> cart.remove_single(apple)\r\n >>> cart.total\r\n 0\r\n\r\n\r\nMultiple carts\r\n--------------\r\n\r\nDjango Carton has support for using multiple carts in the same project.\r\nThe carts would need to be stored in Django session using different session\r\nkeys.\r\n\r\n from carton.cart import Cart\r\n\r\n cart_1 = Cart(session=request.session, session_key='CART-1')\r\n cart_2 = Cart(session=request.session, session_key='CART-2')\r\n\r\n\r\nWorking With Product Model\r\n--------------------------\r\n\r\nDjango Carton needs to know how to list your product objects.\r\n\r\nThe default behaviour is to get the product model using the\r\n`CART_PRODUCT_MODEL` setting and list all products.\r\n\r\nThe default queryset manager is used and all products are\r\nretrieved. You can filter products by defining some lookup\r\nparameters in `CART_PRODUCT_LOOKUP` setting.\r\n\r\n # settings.py\r\n\r\n CART_PRODUCT_LOOKUP = {\r\n 'published': True,\r\n 'status': 'A',\r\n }\r\n\r\n\r\nIf you need further customization of the way product model and queryset\r\nare retrieved, you can always sub-class the default `Cart` and overwrite\r\nthe `get_queryset` method. In that case, you should take into account that:\r\n\r\n* You probably won't need `CART_PRODUCT_MODEL` and `CART_PRODUCT_LOOKUP`\r\n if you get a direct access to your product model and define the\r\n filtering directly on the cart sub-class.\r\n* You probably have to write your own template tag to retrieve the cart\r\n since the default `get_cart` template tag point on the `Cart` class\r\n defined by django-carton.\r\n\r\n\r\nSettings\r\n--------\r\n\r\n### Template Tag Name\r\n\r\nYou can retrieve the cart in templates using\r\n`{% get_cart as my_cart %}`.\r\n\r\nYou can change the name of this template tag using the\r\n`CART_TEMPLATE_TAG_NAME` setting.\r\n\r\n\r\n # In you project settings\r\n CART_TEMPLATE_TAG_NAME = 'get_basket'\r\n\r\n # In templates\r\n {% load carton_tags %}\r\n {% get_basket as my_basket %}\r\n\r\n\r\n### Stale Items\r\n\r\nCart items are associated to products in the database. Sometime a product can be found\r\nin the cart when its database instance has been removed. These items are called stale\r\nitems. By default they are removed from the cart.\r\n\r\n### Session Key\r\n\r\nThe `CART_SESSION_KEY` settings controls the name of the session key.", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/julianogouveia/django-carton/archive/1.2.2.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/julianogouveia/django-carton", "keywords": "", "license": "GPL", "maintainer": "jgouveia", "maintainer_email": "studyclassoficial@gmail.com", "name": "django-carton-no-database", "package_url": "https://pypi.org/project/django-carton-no-database/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-carton-no-database/", "project_urls": { "Download": "https://github.com/julianogouveia/django-carton/archive/1.2.2.zip", "Homepage": "https://github.com/julianogouveia/django-carton" }, "release_url": "https://pypi.org/project/django-carton-no-database/1.2.2/", "requires_dist": null, "requires_python": null, "summary": "django-carton is a simple and lightweight application for shopping carts and wish lists.", "version": "1.2.2" }, "last_serial": 2365222, "releases": { "1.2.1": [], "1.2.2": [] }, "urls": [] }