From 0ae32dfde1285b89d3cd7556dc599f75c0a1e088 Mon Sep 17 00:00:00 2001 From: Miriam Forner Date: Tue, 4 Jul 2023 16:07:39 +0100 Subject: [PATCH 1/2] Move international article page video and image to main content panels --- ...alarticlepage_article_image_ar_and_more.py | 191 ++++++++++++++++++ .../panels/great_international.py | 22 +- great_international/translation.py | 2 + 3 files changed, 199 insertions(+), 16 deletions(-) create mode 100644 great_international/migrations/0162_internationalarticlepage_article_image_ar_and_more.py diff --git a/great_international/migrations/0162_internationalarticlepage_article_image_ar_and_more.py b/great_international/migrations/0162_internationalarticlepage_article_image_ar_and_more.py new file mode 100644 index 00000000..da540d33 --- /dev/null +++ b/great_international/migrations/0162_internationalarticlepage_article_image_ar_and_more.py @@ -0,0 +1,191 @@ +# Generated by Django 4.1.9 on 2023-07-03 09:53 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ('wagtailmedia', '0004_duration_optional_floatfield'), + ('wagtailimages', '0024_index_image_file_hash'), + ('great_international', '0161_alter_internationalarticlelistingpage_tags_and_more'), + ] + + operations = [ + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_ar', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_de', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_en_gb', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_es', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_fr', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_ja', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_pt', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_image_zh_hans', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailimages.image', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_ar', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_de', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_en_gb', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_es', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_fr', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_ja', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_pt', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + migrations.AddField( + model_name='internationalarticlepage', + name='article_video_zh_hans', + field=models.ForeignKey( + blank=True, + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name='+', + to='wagtailmedia.media', + ), + ), + ] diff --git a/great_international/panels/great_international.py b/great_international/panels/great_international.py index eff66e41..6a22b2b9 100644 --- a/great_international/panels/great_international.py +++ b/great_international/panels/great_international.py @@ -276,7 +276,6 @@ class BaseInternationalSectorPagePanels: class InternationalArticlePagePanels: - content_panels = [ FieldPanel('title'), FieldPanel('article_title'), @@ -288,8 +287,10 @@ class InternationalArticlePagePanels: children=[ FieldPanel('article_subheading'), FieldPanel('article_teaser'), - FieldPanel('article_body_text') - ] + FieldPanel('article_body_text'), + FieldPanel('article_image'), + MediaChooserPanel('article_video'), + ], ), MultiFieldPanel( heading='CTA fields', @@ -298,27 +299,16 @@ class InternationalArticlePagePanels: FieldPanel('cta_teaser'), FieldPanel('cta_link_label'), FieldPanel('cta_link'), - ] + ], ), SearchEngineOptimisationPanel(), ] - image_panels = [ - FieldPanel('article_image'), - FieldPanel('article_video', widget=AdminMediaChooser), - ] - - settings_panels = [ - FieldPanel('slug'), - FieldPanel('tags', widget=CheckboxSelectMultiple) - ] + settings_panels = [FieldPanel('slug'), FieldPanel('tags', widget=CheckboxSelectMultiple)] edit_handler = make_translated_interface( content_panels=content_panels, settings_panels=settings_panels, - other_panels=[ - ObjectList(image_panels, heading='Images') - ], ) diff --git a/great_international/translation.py b/great_international/translation.py index e76a6d5b..6b3a9518 100644 --- a/great_international/translation.py +++ b/great_international/translation.py @@ -14,6 +14,8 @@ class InternationalArticlePageTranslationOptions(BaseTranslationOptions): 'type_of_article', 'article_teaser', 'article_body_text', + 'article_video', + 'article_image', 'cta_title', 'cta_teaser', 'cta_link_label', From 899b7c5f3895dca471a2b9be488f142c5acebb18 Mon Sep 17 00:00:00 2001 From: Miriam Forner Date: Tue, 4 Jul 2023 16:04:45 +0100 Subject: [PATCH 2/2] Update serializer class for article video --- great_international/serializers.py | 46 +++++++++++++++--------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/great_international/serializers.py b/great_international/serializers.py index 7a64ca4a..9d277f43 100644 --- a/great_international/serializers.py +++ b/great_international/serializers.py @@ -29,6 +29,28 @@ ) +class GreatMediaSerializer(serializers.Serializer): + title = serializers.CharField() + transcript = serializers.SerializerMethodField() + sources = serializers.SerializerMethodField() + url = serializers.CharField() + thumbnail = serializers.SerializerMethodField() + subtitles = serializers.SerializerMethodField() + + def get_transcript(self, obj): + return obj.greatmedia.transcript + + def get_sources(self, obj): + return obj.greatmedia.sources + + def get_subtitles(self, obj): + return obj.greatmedia.subtitles + + def get_thumbnail(self, obj): + if obj.thumbnail: + return obj.thumbnail.url + + class EntitySummarySerializerBase(serializers.Serializer): """Base class for nested entities that don't need full page representations""" @@ -301,7 +323,7 @@ class InternationalArticlePageSerializer(BasePageSerializer): article_image = wagtail_fields.ImageRenditionField('original') article_image_thumbnail = wagtail_fields.ImageRenditionField('fill-640x360', source='article_image') - article_video = core_fields.VideoField() + article_video = GreatMediaSerializer() article_body_text = core_fields.MarkdownToHTMLField() @@ -329,28 +351,6 @@ def get_freeport_data(self, instance): return serializer.data -class GreatMediaSerializer(serializers.Serializer): - title = serializers.CharField() - transcript = serializers.SerializerMethodField() - sources = serializers.SerializerMethodField() - url = serializers.CharField() - thumbnail = serializers.SerializerMethodField() - subtitles = serializers.SerializerMethodField() - - def get_transcript(self, obj): - return obj.greatmedia.transcript - - def get_sources(self, obj): - return obj.greatmedia.sources - - def get_subtitles(self, obj): - return obj.greatmedia.subtitles - - def get_thumbnail(self, obj): - if obj.thumbnail: - return obj.thumbnail.url - - class InternationalHomePageSerializer(BasePageSerializer): # Note that this is massively cut down from the original version, # but that the older fields still exist on the model (see the comment there)