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
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.1.11 on 2021-10-13 00:18

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('wagtailimages', '0023_add_choose_permissions'),
('wagtailpages', '0043_auto_20211011_2340'),
]

operations = [
migrations.RemoveField(
model_name='buyersguideproductcategory',
name='og_image',
),
migrations.AddField(
model_name='buyersguideproductcategory',
name='share_image',
field=models.ForeignKey(blank=True, help_text='Optional image that will apear when category page is shared.', null=True, on_delete=django.db.models.deletion.SET_NULL, to='wagtailimages.image', verbose_name='Share Image'),
),
]
28 changes: 23 additions & 5 deletions network-api/networkapi/wagtailpages/pagemodels/products.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
from networkapi.wagtailpages.utils import insert_panels_after, get_locale_from_request

# TODO: Move this util function
from networkapi.buyersguide.utils import get_category_og_image_upload_path
from .mixin.snippets import LocalizedSnippet
from networkapi.wagtailpages.utils import get_language_from_request

Expand Down Expand Up @@ -141,17 +140,30 @@ 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.',
)

panels = [
FieldPanel('name'),
FieldPanel('description'),
FieldPanel('featured'),
FieldPanel('hidden'),
FieldPanel('slug'),
Copy link
Contributor

Choose a reason for hiding this comment

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

if we're adding explicit panels, we can hide this autogenerated field by simply omitting it from the panel list.

FieldPanel('sort_order'),
ImageChooserPanel('share_image'),
]

translatable_fields = [
TranslatableField('name'),
TranslatableField('description'),
SynchronizedField('slug'),
SynchronizedField('share_image'),
]

@property
Expand Down Expand Up @@ -1604,6 +1616,12 @@ 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.localized.share_image_id)
if category.description:
setattr(self, 'search_description', category.localized.description)

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

def get_sitemap_urls(self, request):
Expand Down