MozillaFoundation / foundation.mozilla.org

Mozilla Foundation website
https://foundation.mozilla.org
Mozilla Public License 2.0
389 stars 153 forks source link

[PNI] Refactor `ProductPage` metadata #11459

Open jhonatan-lopes opened 11 months ago

jhonatan-lopes commented 11 months ago

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")

┆Issue is synchronized with this Jira Task

data-sync-user commented 3 weeks ago

➤ Mavis Ou commented:

I believe this is still a valid ticket!