User Cart module for Django/DRF projects. Part of GarpixCMS.
Quickstart
Install with pip
$ pip install garpix_cart
Add the garpix_cart to your INSTALLED_APPS:
# settings.py
INSTALLED_APPS = [
# ...
'garpix_cart',
]
Make migrations and migrate database:
$ ./manage.py makemigrations
$ ./manage.py migrate
Add to urls.py:
urlpatterns = [
# ...
path('', include('garpix_cart.urls'))
]
Customize
By default, you will see in settings.py:
GARPIX_CART_SESSION_KEY = 'cart' # cart session key
GARPIX_CART_MIXIN = 'garpix_cart.mixins.CartMixin' # base Cart mixin to model
GARPIX_CART_SESSION_CLASS = 'garpix_cart.base.BaseCartSession' # base cart session core
GARPIX_CART_SESSION_HANDLER_CLASS = 'garpix_cart.base.BaseCartHandler' # base cart handler, which inherit all handlers
Easy way to customize
For example, we want to have our own BaseCartHandler:
override as needed;
# base.py
from garpix_cart.base import BaseCartHandler
class CustomHandler(BaseCartHandler):
def validate(self, products) -> List[Dict[str, Any]]:
return products
Where products is received data from request
Change handler in settings.py;
# settings.py
GARPIX_CART_SESSION_HANDLER_CLASS = 'app.base.CustomHandler'
This work fine!
The hard way to customize
Create your class inherited from abstract;
# base.py
from garpix_cart.abstracts import AbstractCartHandler
class CustomHandler(AbstractCartHandler):
def validate(self, products) -> List[Dict[str, Any]]:
# method validates the data from the request
...
def is_valid(self, products) -> bool:
# check data is valid
...
def make(self, products) -> bool:
# make if data is valid
# always returns modify_session() from CartSession class
...
def error_log(self, products) -> Optional[str]:
# get errors if they raises
...
Change handler in settings.py;
# settings.py
GARPIX_CART_SESSION_HANDLER_CLASS = 'app.base.CustomHandler'
This work fine!
Developed by Garpix / https://garpix.com
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file garpix_cart-1.0.0.tar.gz.
File metadata
- Download URL: garpix_cart-1.0.0.tar.gz
- Upload date:
- Size: 15.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dd156079a4d4b66128ed9b4938905b7ecc9cc3771be21e46d9090618951afd5
|
|
| MD5 |
025653386cdf9fe675570730bbc9653a
|
|
| BLAKE2b-256 |
a36022f6376e0fb6d4827c78ab0927c829be3ba8245e831b6a6cffc26560be43
|
File details
Details for the file garpix_cart-1.0.0-py3-none-any.whl.
File metadata
- Download URL: garpix_cart-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/3.4.1 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ea8f6281392a6730c6076d373eeaaaa7d6a292e84ea5ffd437c388103fb1177
|
|
| MD5 |
8081a47b38ee7ff9d215bc93fc54663f
|
|
| BLAKE2b-256 |
3350b17a36f291b707ad03a47f3d3c972bf47aa7e85179b1cad32fe5d305174c
|