diff options
author | Matthew Lemon <y@yulqen.org> | 2024-10-20 17:03:07 +0100 |
---|---|---|
committer | Matthew Lemon <y@yulqen.org> | 2024-10-20 17:03:07 +0100 |
commit | 97cd01917e26dc21b992b470e6960bf5a64b952b (patch) | |
tree | 1d13a4a2aae1d4bb4ddb91559f5e1942bfdc16dd | |
parent | 6e5370af1f98a3cd2f67b3b730c1b64014be859d (diff) |
bugfix: detail view failed if user had no shopping cart
-rw-r--r-- | alphabetlearning/resources/views.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/alphabetlearning/resources/views.py b/alphabetlearning/resources/views.py index c09ff78..0aae929 100644 --- a/alphabetlearning/resources/views.py +++ b/alphabetlearning/resources/views.py @@ -322,10 +322,12 @@ 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) + try: + cart_items = request.user.shoppingcart.items.all() + if resource["name"] in [r.resource.name for r in cart_items]: + resource.update(in_cart=True) + except: + pass return render(request, "resources/resource_detail.html", {"resource": resource}) |