diff options
Diffstat (limited to 'pyblackbird_cc/resources')
-rw-r--r-- | pyblackbird_cc/resources/models.py | 10 | ||||
-rw-r--r-- | pyblackbird_cc/resources/tests/test_models.py | 2 |
2 files changed, 10 insertions, 2 deletions
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()) |