From 6c469e926fa7fbb31c48ab7a16aa792230968178 Mon Sep 17 00:00:00 2001 From: Erick Otenyo Date: Mon, 19 Feb 2024 09:45:20 +0300 Subject: [PATCH] Fix getting full url for meta image --- base/mixins.py | 7 +++++++ pages/cap/models.py | 2 -- pages/home/models.py | 5 +++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/base/mixins.py b/base/mixins.py index 1d142d98..22ac8d22 100644 --- a/base/mixins.py +++ b/base/mixins.py @@ -1,6 +1,7 @@ from django.utils.translation import gettext_lazy from wagtail.admin.panels import MultiFieldPanel, FieldPanel from wagtail.admin.widgets.slug import SlugInput +from wagtail.api.v2.utils import get_full_url from wagtailcache.cache import WagtailCacheMixin from wagtailmetadata.models import MetadataPageMixin as BaseMetadataPageMixin @@ -27,3 +28,9 @@ class Meta: gettext_lazy("For site menus"), ), ] + + def get_meta_image_url(self, request): + meta_image = self.get_meta_image_rendition() + if meta_image: + return get_full_url(request, meta_image.url) + return None diff --git a/pages/cap/models.py b/pages/cap/models.py index eef9f732..d6b5c42b 100644 --- a/pages/cap/models.py +++ b/pages/cap/models.py @@ -1,5 +1,3 @@ -from datetime import datetime - from capeditor.models import AbstractCapAlertPage from capeditor.pubsub.publish import publish_cap_mqtt_message from django.db import models diff --git a/pages/home/models.py b/pages/home/models.py index a7d57e3b..ec11407b 100644 --- a/pages/home/models.py +++ b/pages/home/models.py @@ -125,6 +125,11 @@ class Meta: verbose_name = _("Home Page") verbose_name_plural = _("Home Pages") + def get_meta_image(self): + if self.search_image: + return self.search_image + return self.hero_banner + def get_context(self, request, *args, **kwargs): context = super(HomePage, self).get_context( request, *args, **kwargs)