Skip to content

Commit

Permalink
feat: add option to clear the metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobi-De committed Mar 29, 2023
1 parent 1190c58 commit 2a68333
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions dj_shop_cart/cart.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ def update_metadata(self, metadata: dict) -> None:
self._metadata.update(metadata)
self.save()

def clear_metadata(self, *keys: list[str]) -> None:
if keys:
for key in keys:
self._metadata.pop(key, None)
else:
self._metadata = {}
self.save()

@classmethod
def new(cls, request: HttpRequest, prefix: str = DEFAULT_CART_PREFIX) -> Cart:
"""Appropriately create a new cart instance. This builder load existing cart if needed."""
Expand Down
1 change: 1 addition & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def my_view(request):
- **products** : A list of associated products.
- **metadata** : A dictionary containing the metadata of the cart.
- **update_metadata(metadata:dict)** : Update the metadata of the cart.
- **clear_metadata(\*keys:list[str])** : Clear the metadata of the cart. Takes an optional list of keys to clear, if no keys are specified, all metadata is cleared.
- **find(\*\*criteria)** : Returns a list of cart items matching the given criteria.
- **find_one(\*\*criteria)** : Returns the first cart item that matches the given criteria, if no match is found return None.
- **variants_group_by_product()** : Return a dictionary with the products ids as keys and a list of variant as values.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dj-shop-cart"
version = "6.0.1"
version = "6.1.0"
description = "Simple django cart manager for your django projects."
authors = ["Tobi DEGNON <[email protected]>"]
license = "MIT"
Expand Down

0 comments on commit 2a68333

Please sign in to comment.