diff --git a/CHANGELOG.md b/CHANGELOG.md index 89a3da2a..ed964099 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,9 +3,11 @@ ## Pre-release ### Implemented enhancements +- No ticket - Make teaser field optional in international articles - No ticket - Add featured industries to Invest home page - CI-321 - About UK landing page - CI-276 - Added `CapitalInvestContactFormPage` and `CapitalInvestContactFormSuccessPage` +- CI-429 - Tree based breadcrumbs can now use `breadcrumbs_label` if available ### Fixed Bugs - CI-426 - Added pdf document upload to why choose uk page for ebook section diff --git a/core/serializers.py b/core/serializers.py index a18caa0d..b972ea9c 100644 --- a/core/serializers.py +++ b/core/serializers.py @@ -10,6 +10,11 @@ class PageTitleAndUrlSerializer(serializers.Serializer): url = serializers.CharField() +class PageBreadcrumbsAndUrlSerializer(serializers.Serializer): + title = serializers.CharField(source='breadcrumbs_label') + url = serializers.CharField() + + class BasePageSerializer(serializers.Serializer): id = serializers.IntegerField() seo_title = serializers.CharField() @@ -27,7 +32,15 @@ def get_tree_based_breadcrumbs(self, instance): breadcrumbs = [ page.specific for page in instance.specific.ancestors_in_app] breadcrumbs.append(instance) - return PageTitleAndUrlSerializer(breadcrumbs, many=True).data + serialized = [] + + for crumb in breadcrumbs: + if hasattr(crumb, 'breadcrumbs_label'): + serialized.append(PageBreadcrumbsAndUrlSerializer(crumb).data) + else: + serialized.append(PageTitleAndUrlSerializer(crumb).data) + + return serialized def get_page_type(self, instance): return instance.__class__.__name__ diff --git a/db_template.sql b/db_template.sql index c5f6c0f9..151211f5 100644 --- a/db_template.sql +++ b/db_template.sql @@ -2,8 +2,8 @@ -- PostgreSQL database dump -- --- Dumped from database version 10.6 (Ubuntu 10.6-0ubuntu0.18.04.1) --- Dumped by pg_dump version 10.6 (Ubuntu 10.6-0ubuntu0.18.04.1) +-- Dumped from database version 9.6.14 +-- Dumped by pg_dump version 11.3 SET statement_timeout = 0; SET lock_timeout = 0; @@ -12,23 +12,10 @@ SET client_encoding = 'UTF8'; SET standard_conforming_strings = on; SELECT pg_catalog.set_config('search_path', '', false); SET check_function_bodies = false; +SET xmloption = content; SET client_min_messages = warning; SET row_security = off; --- --- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; - - --- --- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; - - SET default_tablespace = ''; SET default_with_oids = false; @@ -13227,6 +13214,7 @@ COPY public.django_migrations (id, app, name, applied) FROM stdin; 358 great_international 0064_merge_20190808_0928 2019-08-08 10:30:16.542222+01 359 great_international 0065_auto_20190808_1032 2019-08-08 11:37:15.180475+01 360 great_international 0066_capitalinvestcontactformpage_capitalinvestcontactformsuccesspage 2019-08-09 09:15:15.500538+01 +361 great_international 0067_auto_20190814_0940 2019-08-14 10:42:44.256149+01 \. @@ -14326,7 +14314,7 @@ SELECT pg_catalog.setval('public.django_content_type_id_seq', 121, true); -- Name: django_migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: - -- -SELECT pg_catalog.setval('public.django_migrations_id_seq', 360, true); +SELECT pg_catalog.setval('public.django_migrations_id_seq', 361, true); -- diff --git a/great_international/migrations/0067_auto_20190814_0940.py b/great_international/migrations/0067_auto_20190814_0940.py new file mode 100644 index 00000000..48055ce4 --- /dev/null +++ b/great_international/migrations/0067_auto_20190814_0940.py @@ -0,0 +1,58 @@ +# Generated by Django 2.2.3 on 2019-08-14 09:40 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('great_international', '0066_capitalinvestcontactformpage_capitalinvestcontactformsuccesspage'), + ] + + operations = [ + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page'), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_ar', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_de', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_en_gb', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_es', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_fr', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_ja', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_pt', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + migrations.AlterField( + model_name='internationalarticlepage', + name='article_teaser_zh_hans', + field=models.TextField(blank=True, help_text='This is a subheading that displays when the article is featured on another page', null=True), + ), + ] diff --git a/great_international/models/great_international.py b/great_international/models/great_international.py index a7f2f35d..e230e0ae 100644 --- a/great_international/models/great_international.py +++ b/great_international/models/great_international.py @@ -796,6 +796,7 @@ class InternationalArticlePage(panels.InternationalArticlePagePanels, BaseIntern "below the main title on the article page" ) article_teaser = models.TextField( + blank=True, help_text="This is a subheading that displays when the article " "is featured on another page" ) diff --git a/tests/core/test_serializers.py b/tests/core/test_serializers.py index 9837c6c5..26e4df0d 100644 --- a/tests/core/test_serializers.py +++ b/tests/core/test_serializers.py @@ -1,5 +1,8 @@ import pytest from find_a_supplier.serializers import IndustryPageSerializer +from great_international.serializers import CapitalInvestContactFormSuccessPageSerializer +from tests.great_international.factories import CapitalInvestContactFormPageFactory, \ + CapitalInvestContactFormSuccessPageFactory @pytest.mark.django_db @@ -21,3 +24,29 @@ def test_base_page_serializer(page, rf): assert serializer.data['last_published_at'] == page.last_published_at assert serializer.data['title'] == page.title assert serializer.data['page_type'] == 'IndustryPage' + + +@pytest.mark.django_db +def test_tree_based_breadcrumbs_for_base_page_serializer( + rf, international_root_page +): + form_page = CapitalInvestContactFormPageFactory( + slug='contact', + title_en_gb='form-title', + breadcrumbs_label='breadcrumbs', + parent=international_root_page + ) + + success_page = CapitalInvestContactFormSuccessPageFactory( + slug='success', + title_en_gb="success-title", + parent=form_page + ) + + success_serializer = CapitalInvestContactFormSuccessPageSerializer( + instance=success_page, + context={'request': rf.get('/')} + ) + + assert success_serializer.data['tree_based_breadcrumbs'][0]['title'] == 'breadcrumbs' + assert success_serializer.data['tree_based_breadcrumbs'][1]['title'] == 'success-title' diff --git a/tests/great_international/factories.py b/tests/great_international/factories.py index 7b877511..7d31404a 100644 --- a/tests/great_international/factories.py +++ b/tests/great_international/factories.py @@ -738,3 +738,33 @@ class Meta: title_en_gb = factory.Sequence(lambda n: '123-555-{0}'.format(n)) last_published_at = timezone.now() parent = None + + +class CapitalInvestContactFormPageFactory( + wagtail_factories.PageFactory +): + + class Meta: + model = models.capital_invest.CapitalInvestContactFormPage + + heading = factory.fuzzy.FuzzyText(length=50) + intro = factory.fuzzy.FuzzyText(length=50) + cta_text = factory.fuzzy.FuzzyText(length=50) + slug = factory.Sequence(lambda n: '123-555-{0}'.format(n)) + title_en_gb = factory.Sequence(lambda n: '123-555-{0}'.format(n)) + last_published_at = timezone.now() + parent = None + + +class CapitalInvestContactFormSuccessPageFactory( + wagtail_factories.PageFactory +): + + class Meta: + model = models.capital_invest.CapitalInvestContactFormSuccessPage + + large_text = factory.fuzzy.FuzzyText(length=50) + slug = factory.Sequence(lambda n: '123-555-{0}'.format(n)) + title_en_gb = factory.Sequence(lambda n: '123-555-{0}'.format(n)) + last_published_at = timezone.now() + parent = None