Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7441 category share data #7606

Merged
merged 11 commits into from
Oct 19, 2021
18 changes: 14 additions & 4 deletions network-api/networkapi/wagtailpages/pagemodels/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,20 @@ class BuyersGuideProductCategory(TranslatableMixin, LocalizedSnippet, models.Mod
help_text='Sort ordering number. Same-numbered items sort alphabetically'
)

og_image = models.FileField(
max_length=2048,
help_text='Image to use as OG image',
upload_to=get_category_og_image_upload_path,
share_image = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
verbose_name='Share Image',
help_text='Optional image that will apear when category page is shared.',
)

translatable_fields = [
TranslatableField('name'),
TranslatableField('description'),
SynchronizedField('slug'),
ImageChooserPanel('share_image'),
danielfmiranda marked this conversation as resolved.
Show resolved Hide resolved
]

@property
Expand Down Expand Up @@ -1602,6 +1605,13 @@ def categories_page(self, request, slug):
f' | Mozilla Foundation'
context['template_cache_key_fragment'] = f'{category.slug}_{request.LANGUAGE_CODE}'

# Checking if category has custom metadata, if so, update the share image and description.
if category.share_image:
setattr(self, 'search_image_id', category.share_image_id)
if category.description:
setattr(self, 'search_description', category.description)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is still marked as WIP, but wanted to flag early that we will want to make this work for localized categories too.
I think relying on category.localized should work here?



return render(request, "buyersguide/category_page.html", context)

def get_sitemap_urls(self, request):
Expand Down