aboutsummaryrefslogtreecommitdiffstats
path: root/alphabetlearning/resources/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'alphabetlearning/resources/views.py')
-rw-r--r--alphabetlearning/resources/views.py13
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})