The metadata methods on a PNI's ProductPage contain methods that are already part of other mixins or packages. They must also be combed for N+1 queries.
# TODO: refactor meta methods out as part of: https://github.com/mozilla/foundation.mozilla.org/issues/7828
# See package docs for `get_meta_*` methods: https://pypi.org/project/wagtail-metadata/
def get_meta_title(self):
return gettext("*Privacy Not Included review:") + f" {self.title}"
def get_meta_description(self):
if self.search_description:
return self.search_description
soup = BeautifulSoup(self.blurb, "html.parser")
first_paragraph = soup.find("p")
if first_paragraph:
return first_paragraph.text
return super().get_meta_description()
def get_meta_image_url(self, request):
# Heavy-duty exception handling so the page doesn't crash due to a
# missing sharing image.
try:
return (self.search_image or self.image).get_rendition("original").url
except Exception:
return static("_images/buyers-guide/evergreen-social.png")
The metadata methods on a PNI's
ProductPage
contain methods that are already part of other mixins or packages. They must also be combed for N+1 queries.┆Issue is synchronized with this Jira Task