diff --git a/great_international/panels/great_international.py b/great_international/panels/great_international.py index 4566420c..fd82ddf1 100644 --- a/great_international/panels/great_international.py +++ b/great_international/panels/great_international.py @@ -283,7 +283,7 @@ class InternationalArticlePagePanels: content_panels = [ FieldPanel('title'), FieldPanel('article_title'), - FieldPanel('type_of_article'), + FieldPanel('type_of_article', widget=Select), ImageChooserPanel('hero_image'), MediaChooserPanel('hero_video'), MultiFieldPanel( @@ -312,7 +312,6 @@ class InternationalArticlePagePanels: ] settings_panels = [ - FieldPanel('type_of_article', widget=Select), FieldPanel('slug'), FieldPanel('tags', widget=CheckboxSelectMultiple) ] diff --git a/great_international/serializers.py b/great_international/serializers.py index 561d4a68..7a64ca4a 100644 --- a/great_international/serializers.py +++ b/great_international/serializers.py @@ -312,6 +312,22 @@ class InternationalArticlePageSerializer(BasePageSerializer): tags = core_fields.TagsListField() + freeport_data = serializers.SerializerMethodField() + + def get_freeport_data(self, instance): + if instance.type_of_article == 'Freeport landing': + queryset = InvestmentOpportunityPage.objects.live().public().filter(investment_type__name='Freeport') + if not queryset: + return [] + + serializer = InvestmentOpportunityForListPageSerializer( + queryset, + many=True, + allow_null=True, + context=self.context + ) + return serializer.data + class GreatMediaSerializer(serializers.Serializer): title = serializers.CharField() diff --git a/tests/great_international/test_serializers.py b/tests/great_international/test_serializers.py index df67d3b6..698d821b 100644 --- a/tests/great_international/test_serializers.py +++ b/tests/great_international/test_serializers.py @@ -18,6 +18,7 @@ InvestmentOpportunityForListPageSerializer, InternationalInvestmentSectorPageSerializer, InternationalInvestmentSubSectorPageSerializer, + InternationalArticlePageSerializer ) from tests.core.helpers import make_test_video from tests.great_international.factories import ( @@ -66,6 +67,13 @@ def fdi_investment_type(): ) +@pytest.fixture +def freeport_investment_type(): + return InvestmentTypeFactory( + name='Freeport' + ) + + @pytest.fixture def non_fdi_investment_type(): InvestmentTypeFactory( @@ -1613,3 +1621,48 @@ def test_foreign_direct_investment_form_sucess_page_serializer( assert len(serializer.data['opportunity_list']) == 2 assert serializer.data['opportunity_list'][0]['meta']['slug'] == 'opp_1__fdi' assert serializer.data['opportunity_list'][1]['meta']['slug'] == 'opp_3__fdi' + + +@pytest.mark.django_db +def test_freeport_data(international_root_page, freeport_investment_type, non_fdi_investment_type): + + InvestmentOpportunityPageFactory.create_batch( + 2, + parent=international_root_page, + investment_type=freeport_investment_type + ) + + InvestmentOpportunityPageFactory.create_batch( + 2, + parent=international_root_page, + investment_type=non_fdi_investment_type + ) + + freeport_landing_page = InternationalArticlePageFactory( + type_of_article='Freeport landing' + ) + + freeport_data = InternationalArticlePageSerializer( + instance=freeport_landing_page, + ).get_freeport_data(instance=freeport_landing_page) + + assert len(freeport_data) == 2 + + +@pytest.mark.django_db +def test_freeport_data_has_no_results(international_root_page, non_fdi_investment_type): + InvestmentOpportunityPageFactory.create_batch( + 2, + parent=international_root_page, + investment_type=non_fdi_investment_type + ) + + freeport_landing_page = InternationalArticlePageFactory( + type_of_article='Freeport landing' + ) + + freeport_data = InternationalArticlePageSerializer( + instance=freeport_landing_page, + ).get_freeport_data(instance=freeport_landing_page) + + assert freeport_data == []