From 8c72558ca69a237e36ffff27e1d02ce3bfc0bb51 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Wed, 17 Jan 2024 19:35:13 +0000 Subject: [PATCH] Add alt text for unsplash image URLs --- website/common/models.py | 7 +++++++ website/common/templates/common/listing-item.html | 2 +- website/common/templates/wagtail_base.html | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/website/common/models.py b/website/common/models.py index fb9bedd..ad96dbd 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -195,6 +195,13 @@ class BaseContentPage(BasePage, MetadataMixin): def list_image_url(self) -> Optional[str]: return self.hero_url("small") + @cached_property + def hero_image_alt(self) -> str: + if self.hero_unsplash_photo_id is None: + return "" + + return self.hero_unsplash_photo.data.get("description", "") + def get_meta_url(self) -> str: return self.full_url diff --git a/website/common/templates/common/listing-item.html b/website/common/templates/common/listing-item.html index 0321cb9..92fedea 100644 --- a/website/common/templates/common/listing-item.html +++ b/website/common/templates/common/listing-item.html @@ -6,7 +6,7 @@
{% if page.list_image_url %} - + {{ page.hero_image_alt }} {% endif %}
diff --git a/website/common/templates/wagtail_base.html b/website/common/templates/wagtail_base.html index 9dfb407..4d7bb69 100644 --- a/website/common/templates/wagtail_base.html +++ b/website/common/templates/wagtail_base.html @@ -15,7 +15,7 @@ {% for width, image_url in page.hero_image_urls.items reversed %}{% endfor %} - + {{ page.hero_image_alt }} {% endif %}