From 51bbea4361d4fafe93997ed0f3dae05be8389c96 Mon Sep 17 00:00:00 2001 From: Matthew Lemon Date: Thu, 19 Sep 2024 19:52:02 +0100 Subject: wip: getting the thumbnails of resources --- pyblackbird_cc/payments/views.py | 11 +++++---- pyblackbird_cc/resources/models.py | 3 +++ pyblackbird_cc/resources/tests/test_models.py | 6 +++++ pyblackbird_cc/templates/payments/cart_detail.html | 27 ++++++++++++++-------- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/pyblackbird_cc/payments/views.py b/pyblackbird_cc/payments/views.py index 36f1d84..28ad10d 100644 --- a/pyblackbird_cc/payments/views.py +++ b/pyblackbird_cc/payments/views.py @@ -17,9 +17,6 @@ from .models import ShoppingCart stripe.api_key = settings.STRIPE_SECRET_KEY -def cart(request): - cart = ShoppingCart.objects.get(user=request.user) - return render(request, "cart_detail.html", {"cart": cart}) class CreateCheckoutSessionView(View): @@ -69,12 +66,18 @@ def add_to_cart(request, resource_id): cart_item.save() return redirect("cart_detail") - @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): +# cart, created = ShoppingCart.objects.get_or_create(user=request.user) +# return render(request, "payments/cart_detail.html", {"cart": cart}) + @login_required def checkout(request): diff --git a/pyblackbird_cc/resources/models.py b/pyblackbird_cc/resources/models.py index 6ecf525..7bbf244 100644 --- a/pyblackbird_cc/resources/models.py +++ b/pyblackbird_cc/resources/models.py @@ -115,6 +115,9 @@ 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) + class ResourceType(models.Model): name = models.CharField(max_length=255, null=False) diff --git a/pyblackbird_cc/resources/tests/test_models.py b/pyblackbird_cc/resources/tests/test_models.py index 7398c43..40c13e4 100644 --- a/pyblackbird_cc/resources/tests/test_models.py +++ b/pyblackbird_cc/resources/tests/test_models.py @@ -111,3 +111,9 @@ class TestPDFResourceModel(TestCase): def test_get_pdf_snapshot_filenames(self): self.assertEqual(self.pdf_resource.snapshot_file_names(), ["test_resource_1.jpg"]) + + +@pytest.mark.django_db() +def test_get_urls_of_resource_snapshot_images(resource): + assert len(resource.thumbnail_filenames) == 3 + diff --git a/pyblackbird_cc/templates/payments/cart_detail.html b/pyblackbird_cc/templates/payments/cart_detail.html index 7c51814..3f95b83 100644 --- a/pyblackbird_cc/templates/payments/cart_detail.html +++ b/pyblackbird_cc/templates/payments/cart_detail.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% load static %} - {% block content %} +{% block content %}

My basket

{% lorem %}

@@ -13,23 +13,32 @@ Product Price - Quantity - Total - {% for item in cart_items %} + {% for item in cart.items.all %} - {{ item.product.name }} - ${{ item.product.price }} - {{ item.quantity }} - £{{ item.total }} + +
+

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 }} {% endfor %} - Total: + Total: £{{ cart_total }} -- cgit v1.2.3