aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-19 19:52:02 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-19 19:52:02 +0100
commit51bbea4361d4fafe93997ed0f3dae05be8389c96 (patch)
treeea180b511a9fe76127dc7f60acd5cf74352c40de
parent8c0cbec4a801771c2eda26bba54d4cfcf95ca9d7 (diff)
wip: getting the thumbnails of resources
-rw-r--r--pyblackbird_cc/payments/views.py11
-rw-r--r--pyblackbird_cc/resources/models.py3
-rw-r--r--pyblackbird_cc/resources/tests/test_models.py6
-rw-r--r--pyblackbird_cc/templates/payments/cart_detail.html27
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 %}
<div class="container my-5">
<h1 class="mb-4">My basket</h1>
<p class="text-body-secondary">{% lorem %}</p>
@@ -13,23 +13,32 @@
<tr>
<th>Product</th>
<th>Price</th>
- <th>Quantity</th>
- <th>Total</th>
</tr>
</thead>
<tbody>
- {% for item in cart_items %}
+ {% for item in cart.items.all %}
<tr>
- <td>{{ item.product.name }}</td>
- <td>${{ item.product.price }}</td>
- <td>{{ item.quantity }}</td>
- <td>&#163;{{ item.total }}</td>
+ <td>
+ <div class="d-flex flex-row justify-content-between">
+ <p>TODO: we don't have access to thumbnails yet!</p>
+ <div>
+ {{ item.resource.name }}
+ </div>
+ {% for tn_url, tn_filename in item.resource.thumbnails %}
+ <p>{{ tn_url }}</p>
+ <div>
+ <img class="img-fluid rounded" src="{{ tn_url }}" alt=" {{ tn_filename }}"/>
+ </div>
+ {% endfor %}
+ </div>
+ </td>
+ <td>&#163;{{ item.product.price }}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr>
- <th colspan="3" class="text-end">Total:</th>
+ <th class="text-end">Total:</th>
<th>&#163;{{ cart_total }}</th>
</tr>
</tfoot>