From c121648619c674aaf70cf1efb41ede6f2fe8429c Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 19 Sep 2024 21:02:59 +0100 Subject: Looking crap but getting there - the basket... --- pyblackbird_cc/payments/views.py | 3 - pyblackbird_cc/resources/models.py | 10 ++- pyblackbird_cc/resources/tests/test_models.py | 2 + pyblackbird_cc/templates/payments/cart_detail.html | 71 +++++++++++----------- .../templates/payments/cart_lineitem.html | 17 ++++++ 5 files changed, 61 insertions(+), 42 deletions(-) create mode 100644 pyblackbird_cc/templates/payments/cart_lineitem.html diff --git a/pyblackbird_cc/payments/views.py b/pyblackbird_cc/payments/views.py index 28ad10d..01400bb 100644 --- a/pyblackbird_cc/payments/views.py +++ b/pyblackbird_cc/payments/views.py @@ -69,9 +69,6 @@ def add_to_cart(request, resource_id): @login_required def cart_detail(request): cart, created = ShoppingCart.objects.get_or_create(user=request.user) - # TODO Here we need to iterate over cart_items and extract metadata - # for each one so that we can access thumbnails in the template - #resource_metadata = _extract_metadata_from_resource(resource_obj) return render(request, "payments/cart_detail.html", {"cart": cart}) # def cart_detail(request): diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py index 7bbf244..3dfad06 100644 --- a/pyblackbird_cc/resources/models.py +++ b/pyblackbird_cc/resources/models.py @@ -1,6 +1,9 @@ +from django.conf import settings from django.db import models from django.urls import reverse +from .s3 import get_presigned_obj_url + CURRICULUM_CHOICES = [ ("No curriculum", "No curriculum"), ("English", "English"), @@ -115,8 +118,11 @@ class Resource(models.Model): def get_absolute_url(self): return reverse("resources:resource_detail", kwargs={"resource_id": self.pk}) - def thumbnail_urls(self): - ri = _extract_metadata_from_resource(self) + def thumbnail_urls(self) -> list[str]: + return [ + get_presigned_obj_url(settings.AWS_STORAGE_BUCKET_NAME, f"thumbnails/{f}") + for f in self.thumbnail_filenames + ] class ResourceType(models.Model): diff --git a/pyblackbird_cc/resources/tests/test_models.py b/pyblackbird_cc/resources/tests/test_models.py index 40c13e4..bfc5a38 100644 --- a/pyblackbird_cc/resources/tests/test_models.py +++ b/pyblackbird_cc/resources/tests/test_models.py @@ -116,4 +116,6 @@ class TestPDFResourceModel(TestCase): @pytest.mark.django_db() def test_get_urls_of_resource_snapshot_images(resource): assert len(resource.thumbnail_filenames) == 3 + # crude but it does the job; concatenating a list of URLS into one long sting... + assert "https://ams3.digitaloceanspaces.com" in "".join(resource.thumbnail_urls()) diff --git a/pyblackbird_cc/templates/payments/cart_detail.html b/pyblackbird_cc/templates/payments/cart_detail.html index 3f95b83..e38e2ae 100644 --- a/pyblackbird_cc/templates/payments/cart_detail.html +++ b/pyblackbird_cc/templates/payments/cart_detail.html @@ -6,45 +6,42 @@

My basket

{% lorem %}

{% if cart %} -
-
- - - - - - - - - {% for item in cart.items.all %} - - - - - {% endfor %} - - - - - - - -
ProductPrice
-
-

TODO: we don't have access to thumbnails yet!

-
- {{ item.resource.name }} -
- {% for tn_url, tn_filename in item.resource.thumbnails %} -

{{ tn_url }}

-
-  {{ tn_filename }} -
- {% endfor %} -
-
£{{ item.product.price }}
Total:£{{ cart_total }}
+
+
+
+ +
+
+ + + + + + + + + + {% for item in cart.items.all %} + + + + + {% endfor %} + + + + + + + +
ProductPrice
+ {% include "payments/cart_lineitem.html" with item=item %} + £{{ item.product.price }}
Total:£{{ cart_total }}
+ +
+
Checkout diff --git a/pyblackbird_cc/templates/payments/cart_lineitem.html b/pyblackbird_cc/templates/payments/cart_lineitem.html new file mode 100644 index 0000000..b639a7f --- /dev/null +++ b/pyblackbird_cc/templates/payments/cart_lineitem.html @@ -0,0 +1,17 @@ +
+
+
+ {{ item.resource.name }} +
+
+ {{ item.resource.card_description }} +
+
+ {% for tn_url in item.resource.thumbnail_urls %} +
+ unknown +
+ {% endfor %} +
+
+
-- cgit v1.2.3