diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-20 16:42:21 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-20 16:42:21 +0100 |
commit | fce28f5be8ba8831eed5ccf482fa2abf5432ee89 (patch) | |
tree | 3f0260c44accb04fa46f1e493bed466fff31c871 /alphabetlearning/resources | |
parent | 791cf758caaf25a9375005bdd7f699e614729823 (diff) |
Cart shows items in it; disables buttons if item in basket
- Rough cart icon in navbar
- Shows items in cart
- Styled dependent on existence
- Add to cart buttons disabled if resource in cart, on resource list
page and detail page
- Throws 404 error if trying add item to cart which has no price -
eventually all items will have a price
Diffstat (limited to 'alphabetlearning/resources')
-rw-r--r-- | alphabetlearning/resources/views.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/alphabetlearning/resources/views.py b/alphabetlearning/resources/views.py index 3bf3d22..c09ff78 100644 --- a/alphabetlearning/resources/views.py +++ b/alphabetlearning/resources/views.py @@ -128,6 +128,15 @@ def index(request): resource_list = [_extract_metadata_from_resource(r) for r in resource_objs] + for r in resource_list: + # TODO test for this existing - it will fail if no cart + try: + cart_items = request.user.shoppingcart.items.all() + if r.name in [r.resource.name for r in cart_items]: + r.in_cart = True + except: + pass + # Create a separate queryset for Featured resources featured_resources = [r for r in resource_list if r.feature_slot] featured_resources = sorted(featured_resources, key=lambda resource: resource.feature_slot) @@ -313,6 +322,10 @@ def resource_detail(request, resource_id): "created": resource_metadata.created, "updated": resource_metadata.updated, } + # TODO test for this existing - it will fail if no cart + cart_items = request.user.shoppingcart.items.all() + if resource["name"] in [r.resource.name for r in cart_items]: + resource.update(in_cart=True) return render(request, "resources/resource_detail.html", {"resource": resource}) |