class InternationalTopicLandingPageSerializer(BasePageSerializer):
    landing_page_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='landing_page_title')
    hero_teaser = serializers.CharField(max_length=255)
    hero_image = wagtail_fields.ImageRenditionField('original')

    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='hero_image')

    child_pages = serializers.SerializerMethodField()

    def get_child_pages(self, obj):
        articles_listing_queryset = obj.get_descendants().type(
            InternationalArticleListingPage).live().specific()
        articles_list_serializer = InternationalArticleListingPageSerializer(
            articles_listing_queryset,
            many=True,
            allow_null=True,
            context=self.context)
        campaigns_queryset = obj.get_descendants().type(
            InternationalCampaignPage).live().specific()
        campaigns_serializer = RelatedCampaignPageSerializer(
            campaigns_queryset,
            many=True,
            allow_null=True,
            context=self.context)
        return articles_list_serializer.data + campaigns_serializer.data
class InternationalCuratedTopicLandingPageSerializer(BasePageSerializer):
    display_title = serializers.CharField()

    hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='hero_image')

    teaser = serializers.CharField()

    feature_section_heading = serializers.CharField()

    features_large = serializers.SerializerMethodField()

    features_small = serializers.SerializerMethodField()

    def get_features(self, instance, *positions):
        data = [
            FeatureProxyDataWrapper(
                instance=instance,
                position_number=num,
            ) for num in positions
        ]
        serializer = FeatureSerializer(data, many=True)
        return serializer.data

    def get_features_large(self, instance):
        return self.get_features(instance, 'one', 'two')

    def get_features_small(self, instance):
        return self.get_features(instance, 'three', 'four', 'five')
class FeatureSerializer(serializers.Serializer):
    heading = serializers.CharField()
    content = core_fields.MarkdownToHTMLField()
    image = wagtail_fields.ImageRenditionField('original')
    image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='image')
    url = serializers.CharField()
Example #4
0
class AboutDitServicesPageSerializer(BasePageSerializer, HeroSerializer):
    breadcrumbs_label = serializers.CharField()
    hero_title = serializers.CharField()
    featured_description = serializers.CharField()
    teaser = core_fields.MarkdownToHTMLField()
    ebook_section_image = wagtail_fields.ImageRenditionField('fill-299x423')
    ebook_section_image_alt_text = serializers.CharField()
    ebook_section_body = core_fields.MarkdownToHTMLField()
    ebook_section_cta_text = serializers.CharField()
    ebook_section_cta_link = serializers.CharField()
    case_study_image = wagtail_fields.ImageRenditionField('original')
    case_study_title = serializers.CharField()
    case_study_text = serializers.CharField()
    case_study_cta_text = serializers.CharField()
    case_study_cta_link = serializers.CharField()
    contact_us_section_title = serializers.CharField()
    contact_us_section_summary = core_fields.MarkdownToHTMLField()
    contact_us_section_cta_text = serializers.CharField()
    contact_us_section_cta_link = serializers.CharField()
    about_dit_services_fields = serializers.SerializerMethodField()

    def get_about_dit_services_fields(self, instance):
        serializer = AboutDitServiceFieldSerializer(
            instance.about_dit_services_fields.all(),
            many=True,
            allow_null=True,
            context=self.context)
        return serializer.data
class InternationalArticlePageSerializer(PageWithRelatedPagesSerializer):
    article_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='article_title')
    article_teaser = serializers.CharField(max_length=255)
    article_image = wagtail_fields.ImageRenditionField('original')
    article_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='article_image')
    article_body_text = core_fields.MarkdownToHTMLField()
class ArticlePageSerializer(PageWithRelatedPagesSerializer):
    article_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='article_title')
    article_teaser = serializers.CharField(max_length=255)
    article_image = wagtail_fields.ImageRenditionField('original')
    article_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360', source='article_image')
    article_body_text = core_fields.MarkdownToHTMLField()
    tags = core_fields.TagsListField()
class RelatedArticlePageSerializer(BasePageSerializer):
    """Separate serializer for related article pages so we don't end up with
    infinite nesting of related pages inside an article page"""

    article_title = serializers.CharField(max_length=255)
    article_teaser = serializers.CharField(max_length=255)
    article_image = wagtail_fields.ImageRenditionField('original')
    article_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='article_image')
Example #8
0
class InvestmentAtlasLandingPageSerializer(BasePageSerializer):
    IMAGE_RENDITION_SPEC = "original"
    MOBILE_IMAGE_RENDITION_SPEC = "original"

    breadcrumbs_label = serializers.CharField()
    hero_image = wagtail_fields.ImageRenditionField(IMAGE_RENDITION_SPEC)
    mobile_hero_image = wagtail_fields.ImageRenditionField(
        MOBILE_IMAGE_RENDITION_SPEC, )
    hero_video = GreatMediaSerializer()
    hero_strapline = serializers.CharField()
    downpage_sections = StreamFieldSerializer()
Example #9
0
class CountryGuidePageSerializer(PageWithRelatedPagesSerializer):
    hero_image = wagtail_fields.ImageRenditionField('original')
    heading = serializers.CharField(max_length=255)
    sub_heading = serializers.CharField(max_length=255)
    heading_teaser = serializers.CharField()
    hero_image = wagtail_fields.ImageRenditionField('original')

    section_one_body = core_fields.MarkdownToHTMLField()
    section_one_image = wagtail_fields.ImageRenditionField('fill-640x360')
    section_one_image_caption = serializers.CharField(max_length=255)
    section_one_image_caption_company = serializers.CharField(max_length=255)

    section_two_heading = serializers.CharField(max_length=255)
    section_two_teaser = serializers.CharField()

    statistics = serializers.SerializerMethodField()
    accordions = serializers.SerializerMethodField()
    fact_sheet = serializers.SerializerMethodField()

    help_market_guide_cta_link = serializers.CharField(max_length=255)

    def get_fact_sheet(self, instance):
        data = {
            'fact_sheet_title':
            instance.fact_sheet_title,
            'fact_sheet_teaser':
            instance.fact_sheet_teaser,
            'columns': [
                FactSheetColumnProxyDataWrapper(instance=instance,
                                                position_number=num)
                for num in ['1', '2']
            ]
        }
        return FactSheetSerializer(data).data

    def get_statistics(self, instance):
        data = [
            StatisticProxyDataWrapper(instance=instance, position_number=num)
            for num in ['1', '2', '3', '4', '5', '6']
        ]
        serializer = StatisticSerializer(data, many=True)
        return serializer.data

    def get_accordions(self, instance):
        data = [
            AccordionProxyDataWrapper(instance=instance, position_number=num)
            for num in ['1', '2', '3', '4', '5', '6']
        ]
        serializer = AccordionSerializer(data, many=True)
        return serializer.data
Example #10
0
class InternationalArticleListingPageSerializer(BasePageSerializer):
    landing_page_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='landing_page_title')
    hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='hero_image')

    articles_count = serializers.IntegerField()
    list_teaser = core_fields.MarkdownToHTMLField(allow_null=True)
    hero_teaser = serializers.CharField(allow_null=True)
    child_pages = serializers.SerializerMethodField()
    localised_child_pages = serializers.SerializerMethodField()

    def get_localised_child_pages(self, obj):
        data = []
        if 'region' in self.context:
            slug = f'{obj.slug}-{self.context["region"]}'
            folder = InternationalLocalisedFolderPage.objects.filter(slug=slug)
            if folder.exists():
                articles_queryset = folder[0].get_descendants().type(
                    InternationalArticlePage).live().specific()
                articles = RelatedArticlePageSerializer(articles_queryset,
                                                        many=True,
                                                        allow_null=True,
                                                        context=self.context)
                campaigns_queryset = folder[0].get_descendants().type(
                    InternationalCampaignPage).live().specific()

                campaigns = RelatedCampaignPageSerializer(campaigns_queryset,
                                                          many=True,
                                                          allow_null=True,
                                                          context=self.context)
                data = articles.data + campaigns.data
        return data

    def get_child_pages(self, obj):
        articles_queryset = obj.get_descendants().type(
            InternationalArticlePage).live().specific()
        articles = RelatedArticlePageSerializer(articles_queryset,
                                                many=True,
                                                allow_null=True,
                                                context=self.context)
        campaigns_queryset = obj.get_descendants().type(
            InternationalCampaignPage).live().specific()
        campaigns = RelatedCampaignPageSerializer(campaigns_queryset,
                                                  many=True,
                                                  allow_null=True,
                                                  context=self.context)
        return articles.data + campaigns.data
Example #11
0
class GetFinancePageSerializer(BasePageSerializer):
    breadcrumbs_label = serializers.CharField()
    hero_text = core_fields.MarkdownToHTMLField()
    hero_image = wagtail_fields.ImageRenditionField('original')
    ukef_logo = wagtail_fields.ImageRenditionField('original')
    contact_proposition = core_fields.MarkdownToHTMLField()
    contact_button = serializers.CharField()
    advantages_title = serializers.CharField()
    advantages_one = core_fields.MarkdownToHTMLField()
    advantages_one_icon = wagtail_fields.ImageRenditionField('original')
    advantages_two = core_fields.MarkdownToHTMLField()
    advantages_two_icon = wagtail_fields.ImageRenditionField('original')
    advantages_three = core_fields.MarkdownToHTMLField()
    advantages_three_icon = wagtail_fields.ImageRenditionField('original')
    evidence = core_fields.MarkdownToHTMLField()
    evidence_video = core_fields.VideoField()
Example #12
0
class InternationalHomePageSerializer(PageWithRelatedPagesSerializer):
    news_title = serializers.CharField(max_length=255)
    tariffs_title = serializers.CharField(max_length=255)
    tariffs_description = core_fields.MarkdownToHTMLField()
    tariffs_link = serializers.URLField()
    tariffs_image = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg')
class AccordionSerializer(serializers.Serializer):
    icon = wagtail_fields.ImageRenditionField('original')
    title = serializers.CharField()
    teaser = serializers.CharField()
    case_study = AccordionCaseStudySerializer()
    subsections = AccordionSubsectionSerializer(many=True)
    statistics = StatisticSubsectionSerializer(many=True)
class ArticleListingPageSerializer(BasePageSerializer,
                                   ChildPagesSerializerHelper):
    landing_page_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='landing_page_title')
    hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360', source='hero_image')

    articles_count = serializers.IntegerField()
    list_teaser = core_fields.MarkdownToHTMLField(allow_null=True)
    hero_teaser = serializers.CharField(allow_null=True)
    articles = serializers.SerializerMethodField()

    def get_articles(self, obj):
        return self.get_child_pages_data_for(obj, ArticlePage,
                                             ArticlePageSerializer)
Example #15
0
class RelatedCampaignPageSerializer(BasePageSerializer):
    title = serializers.CharField(max_length=255, source='campaign_heading')
    subheading = serializers.CharField(max_length=255,
                                       source='campaign_subheading')
    teaser = serializers.CharField(max_length=255, source='campaign_teaser')
    thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360', source='campaign_hero_image')
Example #16
0
class SectorPageSerializer(BasePageSerializer, ChildPagesSerializerHelper):
    featured = serializers.BooleanField()
    description = serializers.CharField()
    heading = serializers.CharField(max_length=255)
    hero_image = wagtail_fields.ImageRenditionField('original')
    pullout = serializers.SerializerMethodField()
    subsections = serializers.SerializerMethodField()
    children_sectors = serializers.SerializerMethodField()

    def get_pullout(self, instance):
        return PulloutSerializer({
            'text': instance.pullout_text,
            'stat': instance.pullout_stat,
            'stat_text': instance.pullout_stat_text
        }).data

    def get_subsections(self, instance):
        data = [
            SubsectionProxyDataWrapper(instance=instance, suffix=num)
            for num in ONE_TO_SEVEN_WORDS
        ]
        serializer = SubsectionSerializer(data, many=True)
        return serializer.data

    def get_children_sectors(self, instance):
        return self.get_child_pages_data_for(instance, SectorPage,
                                             SectorPageSerializer)
Example #17
0
class SectorPageSerializer(BasePageSerializer):
    featured = serializers.BooleanField()
    description = serializers.CharField()
    heading = serializers.CharField(max_length=255)
    hero_image = wagtail_fields.ImageRenditionField('original')
    pullout = serializers.SerializerMethodField()
    subsections = serializers.SerializerMethodField()
    children_sectors = serializers.SerializerMethodField()

    def get_pullout(self, instance):
        return PulloutSerializer({
            'text': instance.pullout_text,
            'stat': instance.pullout_stat,
            'stat_text': instance.pullout_stat_text
        }).data

    def get_subsections(self, instance):
        data = [
            SubsectionProxyDataWrapper(instance=instance, suffix=num)
            for num in ONE_TO_SEVEN_WORDS
        ]
        serializer = SubsectionSerializer(data, many=True)
        return serializer.data

    def get_children_sectors(self, instance):
        from .models import SectorPage
        queryset = instance.get_descendants().type(
            SectorPage).live().specific()
        serializer = SectorPageSerializer(queryset,
                                          many=True,
                                          allow_null=True,
                                          context=self.context)
        return serializer.data
Example #18
0
class SectorLandingPageGenericSerializer(BasePageSerializer,
                                         ChildPagesSerializerHelper):
    """This can be used for SectorLandingPage and RegionalLandingPage"""
    heading = serializers.CharField(max_length=255)
    hero_image = wagtail_fields.ImageRenditionField('original')
    children_sectors = serializers.SerializerMethodField()

    def get_children_sectors(self, instance):
        return self.get_child_pages_data_for(instance, SectorPage,
                                             SectorPageSerializer)
Example #19
0
class ArticleListingPageSerializer(BasePageSerializer):
    landing_page_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='landing_page_title')
    hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='hero_image')

    articles_count = serializers.IntegerField()
    list_teaser = core_fields.MarkdownToHTMLField(allow_null=True)
    hero_teaser = serializers.CharField(allow_null=True)
    articles = serializers.SerializerMethodField()

    def get_articles(self, obj):
        queryset = obj.get_descendants().type(ArticlePage).live().specific()
        serializer = ArticlePageSerializer(queryset,
                                           many=True,
                                           allow_null=True,
                                           context=self.context)
        return serializer.data
Example #20
0
class CountryGuidePageSerializer(PageWithRelatedPagesSerializer):
    landing_page_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='landing_page_title')
    hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='hero_image')

    articles_count = serializers.IntegerField()

    section_one_heading = serializers.CharField()
    section_one_content = core_fields.MarkdownToHTMLField()
    selling_point_one_icon = wagtail_fields.ImageRenditionField('original')
    selling_point_one_heading = serializers.CharField()
    selling_point_one_content = core_fields.MarkdownToHTMLField()

    selling_point_two_icon = wagtail_fields.ImageRenditionField('original')
    selling_point_two_heading = serializers.CharField()
    selling_point_two_content = core_fields.MarkdownToHTMLField()

    selling_point_three_icon = wagtail_fields.ImageRenditionField('original')
    selling_point_three_heading = serializers.CharField()
    selling_point_three_content = core_fields.MarkdownToHTMLField()

    section_two_heading = serializers.CharField()
    section_two_content = core_fields.MarkdownToHTMLField()

    related_content_heading = serializers.CharField()
    related_content_intro = core_fields.MarkdownToHTMLField()

    articles = serializers.SerializerMethodField()

    def get_articles(self, obj):
        queryset = obj.get_descendants().type(
            ArticlePage
        ).live().specific()
        serializer = ArticlePageSerializer(
            queryset,
            many=True,
            allow_null=True,
            context=self.context
        )
        return serializer.data
Example #21
0
class IndustryLandingPageSerializer(BasePageSerializer):
    hero_image = wagtail_fields.ImageRenditionField('original')
    mobile_hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_caption = serializers.CharField()
    breadcrumbs_label = serializers.CharField()
    breadcrumbs = core_fields.BreadcrumbsField(
        service_name=cms.FIND_A_SUPPLIER)
    hero_title = serializers.CharField()
    proposition_text = serializers.CharField()
    call_to_action_text = serializers.CharField()
    more_industries_title = serializers.CharField()
    industries = serializers.SerializerMethodField()

    def get_industries(self, instance):
        queryset = IndustryPage.objects.all().live().order_by('slug')
        serializer = IndustryPageSerializer(queryset,
                                            many=True,
                                            allow_null=True,
                                            context=self.context)
        return serializer.data
Example #22
0
class InternationalArticlePageSerializer(BasePageSerializer):
    type_of_article = serializers.CharField()

    display_title = serializers.CharField(source='article_title')
    article_title = serializers.CharField()
    article_teaser = serializers.CharField()
    article_subheading = serializers.CharField()

    article_image = wagtail_fields.ImageRenditionField('original')
    article_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360', source='article_image')
    article_video = core_fields.VideoField()

    article_body_text = core_fields.MarkdownToHTMLField()

    cta_title = serializers.CharField()
    cta_teaser = serializers.CharField()
    cta_link_label = serializers.CharField()
    cta_link = serializers.CharField()

    tags = core_fields.TagsListField()
Example #23
0
class InternationalGuideLandingPageSerializer(BasePageSerializer):

    display_title = serializers.CharField()

    hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='hero_image')

    teaser = serializers.CharField()

    section_one_content = core_fields.MarkdownToHTMLField()
    section_one_image = wagtail_fields.ImageRenditionField('original')
    section_one_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='section_one_image')
    section_one_image_caption = serializers.CharField()

    section_two_heading = serializers.CharField()
    section_two_teaser = serializers.CharField()
    section_two_button_text = serializers.CharField()
    section_two_button_url = serializers.CharField()
    section_two_image = wagtail_fields.ImageRenditionField('original')
    section_two_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360|jpegquality-60|format-jpeg', source='section_two_image')

    guides_section_heading = serializers.CharField()
    guides = serializers.SerializerMethodField()

    def get_guides(self, obj):
        article_list = (obj.get_descendants().type(
            InternationalArticlePage).live().specific())[:9]
        serializer = RelatedArticlePageSerializer(article_list, many=True)
        return serializer.data
Example #24
0
class InternationalTradeHomePageSerializer(BasePageSerializer):
    hero_image = wagtail_fields.ImageRenditionField('original')
    mobile_hero_image = wagtail_fields.ImageRenditionField('original')
    hero_image_caption = serializers.CharField()
    breadcrumbs_label = serializers.CharField()
    breadcrumbs = core_fields.BreadcrumbsField(
        service_name=cms.FIND_A_SUPPLIER)
    hero_text = core_fields.MarkdownToHTMLField()
    search_field_placeholder = serializers.CharField()
    search_button_text = serializers.CharField()
    proposition_text = core_fields.MarkdownToHTMLField()
    call_to_action_text = serializers.CharField()
    industries_list_text = core_fields.MarkdownToHTMLField()
    industries_list_call_to_action_text = serializers.CharField()
    services_list_text = core_fields.MarkdownToHTMLField()
    services_column_one = core_fields.MarkdownToHTMLField()
    services_column_two = core_fields.MarkdownToHTMLField()
    services_column_three = core_fields.MarkdownToHTMLField()
    services_column_four = core_fields.MarkdownToHTMLField()
    services_column_one_icon = wagtail_fields.ImageRenditionField('original')
    services_column_two_icon = wagtail_fields.ImageRenditionField('original')
    services_column_three_icon = wagtail_fields.ImageRenditionField('original')
    services_column_four_icon = wagtail_fields.ImageRenditionField('original')
    how_we_help_cta_text = serializers.CharField(max_length=255)
    how_we_help_cta_link = serializers.CharField(max_length=255)
    industries = serializers.SerializerMethodField()

    def get_industries(self, instance):
        queryset = InternationalInvestmentSectorPage.objects.filter(
            live=True).order_by('slug')[:3]
        serializer = InternationalInvestmentSectorPageSerializer(
            queryset, many=True, allow_null=True, context=self.context)
        return serializer.data
Example #25
0
class WhyInvestInTheUKPageSerializer(
        BasePageSerializer,
        HeroSerializer,
):
    IMAGE_RENDITION_SPEC = "fill-960x540"

    hero_video = GreatMediaSerializer()
    strapline = serializers.CharField()
    introduction = core_fields.MarkdownToHTMLField()
    intro_image = wagtail_fields.ImageRenditionField(IMAGE_RENDITION_SPEC)
    uk_strength_title = serializers.CharField()
    uk_strength_intro = serializers.CharField()
    uk_strength_panels = StreamFieldSerializer()
Example #26
0
class InvestmentGeneralContentPageSerializer(
        BasePageSerializer,
        HeroSerializer,
):
    IMAGE_RENDITION_SPEC = "fill-960x540"

    # title comes from BasePageSerializer
    # hero_image comes from HeroSerializer
    strapline = serializers.CharField()
    introduction = core_fields.MarkdownToHTMLField()
    intro_image = wagtail_fields.ImageRenditionField(IMAGE_RENDITION_SPEC)
    hero_video = GreatMediaSerializer()
    main_content = StreamFieldSerializer()
Example #27
0
class InvestHomePageSerializer(BasePageSerializer):
    heading = serializers.CharField(max_length=255)
    sub_heading = serializers.CharField(max_length=255)
    hero_image = wagtail_fields.ImageRenditionField('original')
    subsections = serializers.SerializerMethodField()
    sector_title = serializers.CharField(max_length=255)
    sector_button_text = serializers.CharField(max_length=255)
    setup_guide_title = serializers.CharField(max_length=255)
    setup_guide_lead_in = serializers.CharField(max_length=255,
                                                allow_null=True)
    how_we_help_title = serializers.CharField(max_length=255)
    how_we_help_lead_in = serializers.CharField(max_length=255)
    how_we_help = serializers.SerializerMethodField()
    sectors = serializers.SerializerMethodField()
    guides = serializers.SerializerMethodField()

    def get_how_we_help(self, instance):
        data = [
            HowWeHelpProxyDataWrapper(instance=instance, suffix=num)
            for num in ONE_TO_SIX_WORDS
        ]
        serializer = HowWeHelpSerializer(data, many=True)
        return serializer.data

    def get_subsections(self, instance):
        data = [
            SubsectionProxyDataWrapper(instance=instance, suffix=num)
            for num in ONE_TO_SEVEN_WORDS
        ]
        serializer = SubsectionSerializer(data, many=True)
        return serializer.data

    def get_sectors(self, instance):
        from .models import SectorPage
        queryset = SectorPage.objects.all().filter(
            featured=True).live().order_by('heading')
        serializer = SectorPageSerializer(queryset,
                                          many=True,
                                          allow_null=True,
                                          context=self.context)
        return serializer.data

    def get_guides(self, instance):
        from .models import SetupGuidePage
        queryset = SetupGuidePage.objects.all().live().order_by('heading')
        serializer = SetupGuidePageSerializer(queryset,
                                              many=True,
                                              allow_null=True,
                                              context=self.context)
        return serializer.data
class TopicLandingPageSerializer(BasePageSerializer,
                                 ChildPagesSerializerHelper):
    landing_page_title = serializers.CharField(max_length=255)
    display_title = serializers.CharField(source='landing_page_title')
    hero_teaser = serializers.CharField(max_length=255)
    hero_image = wagtail_fields.ImageRenditionField('original')
    banner_text = core_fields.MarkdownToHTMLField()
    hero_image_thumbnail = wagtail_fields.ImageRenditionField(
        'fill-640x360', source='hero_image')

    teaser = serializers.CharField()

    child_pages = serializers.SerializerMethodField()

    def get_child_pages(self, obj):
        articles = self.get_child_pages_data_for(obj, ArticleListingPage,
                                                 ArticleListingPageSerializer)
        superregions = self.get_child_pages_data_for(
            obj, SuperregionPage, SuperregionPageSerializer)
        country_guides = self.get_child_pages_data_for(
            obj, CountryGuidePage, CountryGuidePageSerializer)
        country_guides = sorted(country_guides, key=lambda x: x['heading'])

        return articles + superregions + country_guides
Example #29
0
class SectorLandingPageGenericSerializer(BasePageSerializer):
    """This can be used for SectorLandingPage and RegionalLandingPage"""
    heading = serializers.CharField(max_length=255)
    hero_image = wagtail_fields.ImageRenditionField('original')
    children_sectors = serializers.SerializerMethodField()

    def get_children_sectors(self, instance):
        from .models import SectorPage
        queryset = instance.get_descendants().type(
            SectorPage).live().specific()
        serializer = SectorPageSerializer(queryset,
                                          many=True,
                                          allow_null=True,
                                          context=self.context)
        return serializer.data
Example #30
0
class RelatedInvestmentOpportunityPageSerializer(BasePageSerializer):
    """Less detailed version of an InvestmentOpportunity - for instance used
    by InvestmentOpportunityPageSerializer.get_related_opportunities
    and AboutUkRegionPageSerializer.get_related_opportunities"""

    # title comes from BasePageSerializer
    thumbnail_image = wagtail_fields.ImageRenditionField('fill-640x360',
                                                         source='hero_image')

    opportunity_summary = serializers.CharField()
    regions = serializers.SerializerMethodField()
    sectors = serializers.SerializerMethodField()
    sub_sectors = serializers.SerializerMethodField()

    def _get_regions(self, instance):
        return set([
            item.value['region'] for item in instance.regions_with_locations
            if item.value['region'].live
        ])

    def get_regions(self, instance):
        related_regions = self._get_regions(instance)
        serializer = MinimalRegionPageSummarySerializer(
            related_regions,
            many=True,
            read_only=True,
        )
        return serializer.data

    def get_sectors(self, instance):
        # Note: This serializer is more verbose than we _need_ here
        serializer = RelatedSectorSerializer(instance.related_sectors.all(),
                                             many=True,
                                             allow_null=True,
                                             context=self.context)
        return serializer.data

    def get_sub_sectors(self, instance):
        # Note: This serializer is more verbose than we _need_ here
        serializer = RelatedSubSectorSerializer(
            instance.related_sub_sectors.all(),
            many=True,
            allow_null=True,
            context=self.context)
        sub_sectors_list = [
            sub_sector['related_sub_sector'] for sub_sector in serializer.data
        ]
        return sub_sectors_list