aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-09-19 21:02:59 +0100
committerMatthew Lemon <y@yulqen.org>2024-09-19 21:02:59 +0100
commitc121648619c674aaf70cf1efb41ede6f2fe8429c (patch)
tree5da07012f616bd53c73ffcf91ae52d8033d44b73
parent51bbea4361d4fafe93997ed0f3dae05be8389c96 (diff)
Looking crap but getting there - the basket...
-rw-r--r--pyblackbird_cc/payments/views.py3
-rw-r--r--pyblackbird_cc/resources/models.py10
-rw-r--r--pyblackbird_cc/resources/tests/test_models.py2
-rw-r--r--pyblackbird_cc/templates/payments/cart_detail.html71
-rw-r--r--pyblackbird_cc/templates/payments/cart_lineitem.html17
5 files changed, 61 insertions, 42 deletions
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 @@
<h1 class="mb-4">My basket</h1>
<p class="text-body-secondary">{% lorem %}</p>
{% if cart %}
- <div class="my-5 bg-secondary-subtle border border-1 rounded border-dark">
- <div class="my-4 bg-white rounded">
- <table class="table">
- <thead>
- <tr>
- <th>Product</th>
- <th>Price</th>
- </tr>
- </thead>
- <tbody>
- {% for item in cart.items.all %}
- <tr>
- <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 class="text-end">Total:</th>
- <th>&#163;{{ cart_total }}</th>
- </tr>
- </tfoot>
- </table>
+ <div class="row justify-content-md-center">
+ <div class="col-8 my-5 bg-secondary-subtle border border-1 rounded border-dark">
+ <div class="my-4 bg-white rounded">
+
+ <div class="d-flex">
+ </div>
+
+ <table class="table">
+ <thead>
+ <tr>
+ <th>Product</th>
+ <th>Price</th>
+ </tr>
+ </thead>
+ <tbody>
+ {% for item in cart.items.all %}
+ <tr>
+ <td>
+ {% include "payments/cart_lineitem.html" with item=item %}
+ </td>
+ <td>&#163;{{ item.product.price }}</td>
+ </tr>
+ {% endfor %}
+ </tbody>
+ <tfoot>
+ <tr>
+ <th class="text-end">Total:</th>
+ <th>&#163;{{ cart_total }}</th>
+ </tr>
+ </tfoot>
+ </table>
+
+ </div>
</div>
+
</div>
<div class="d-flex justify-content-end">
<a href="#" class="btn btn-primary">Checkout</a>
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 @@
+<div class="container my-2">
+ <div class="col-10">
+ <div class="p-2 border border-1 border-success">
+ {{ item.resource.name }}
+ </div>
+ <div class="p-2 border border-1 border-success">
+ {{ item.resource.card_description }}
+ </div>
+ <div class="d-flex flex-row border border-2 border-danger p-1">
+ {% for tn_url in item.resource.thumbnail_urls %}
+ <div class="flex-shrink border border-2 border-alert p-1">
+ <img class="img-fluid rounded" src="{{ tn_url }}" alt="unknown"/>
+ </div>
+ {% endfor %}
+ </div>
+ </div>
+</div>