diff --git a/CHANGELOG.md b/CHANGELOG.md index 3604dc8f..f7d19dde 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Pre-release ### Implemented enhancements +- XOT-1275 - Add MADB link field to country guide ### Fixed bugs diff --git a/export_readiness/migrations/0073_auto_20200203_1333.py b/export_readiness/migrations/0073_auto_20200203_1333.py new file mode 100644 index 00000000..a8d8d6c2 --- /dev/null +++ b/export_readiness/migrations/0073_auto_20200203_1333.py @@ -0,0 +1,50 @@ +# Generated by Django 2.2.6 on 2020-02-03 13:33 + +import logging + + +import core.model_fields +from django.db import migrations, models + +import pycountry + + +logger = logging.getLogger(__name__) + + +def set_duties_and_custom_procedures_cta_link(apps, schema_editor): + url = 'https://www.check-duties-customs-exporting-goods.service.gov.uk/searchproduct?d=' + CountryGuidePage = apps.get_model('export_readiness', 'CountryGuidePage') + for guide in CountryGuidePage.objects.all(): + try: + matches = pycountry.countries.search_fuzzy(guide.country.name) + except LookupError: + logger.warn(f'no country match for {guide.country.name}') + else: + guide.duties_and_custom_procedures_cta_link = f'{url}{matches[0].alpha_2}' + guide.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ('export_readiness', '0072_auto_20191212_1403'), + ] + + operations = [ + migrations.RemoveField( + model_name='countryguidepage', + name='help_market_guide_cta_link', + ), + migrations.AddField( + model_name='countryguidepage', + name='duties_and_custom_procedures_cta_link', + field=models.URLField(blank=True, null=True, verbose_name='Check duties and customs procedures for exporting goods'), + ), + migrations.AlterField( + model_name='homepage', + name='madb_content', + field=core.model_fields.MarkdownField(blank=True, null=True, verbose_name='Content'), + ), + migrations.RunPython(set_duties_and_custom_procedures_cta_link, reverse_code=migrations.RunPython.noop) + ] diff --git a/export_readiness/models.py b/export_readiness/models.py index 13ac2da9..202a387e 100644 --- a/export_readiness/models.py +++ b/export_readiness/models.py @@ -1020,8 +1020,9 @@ class Meta: ) # need help - help_market_guide_cta_link = models.CharField( - max_length=255, blank=True, verbose_name='GOV.UK country guide URL') + duties_and_custom_procedures_cta_link = models.URLField( + blank=True, null=True, verbose_name='Check duties and customs procedures for exporting goods' + ) # related pages related_page_one = models.ForeignKey( diff --git a/export_readiness/panels.py b/export_readiness/panels.py index 15bc0267..aa9dc0e6 100644 --- a/export_readiness/panels.py +++ b/export_readiness/panels.py @@ -889,7 +889,7 @@ class CountryGuidePagePanels: heading='Need help', classname='collapsible', children=[ - FieldPanel('help_market_guide_cta_link') + FieldPanel('duties_and_custom_procedures_cta_link') ] ), MultiFieldPanel( diff --git a/export_readiness/serializers.py b/export_readiness/serializers.py index 860d1454..0fafd55f 100644 --- a/export_readiness/serializers.py +++ b/export_readiness/serializers.py @@ -419,7 +419,7 @@ class CountryGuidePageSerializer(PageWithRelatedPagesSerializer, HeroSerializer) accordions = serializers.SerializerMethodField() fact_sheet = serializers.SerializerMethodField() - help_market_guide_cta_link = serializers.CharField(max_length=255) + duties_and_custom_procedures_cta_link = serializers.CharField(max_length=255) tags = core_fields.TagsListField() region = serializers.CharField(allow_null=True, source='country.region.name') diff --git a/requirements.in b/requirements.in index 17d69b98..e9c30bb1 100644 --- a/requirements.in +++ b/requirements.in @@ -33,3 +33,4 @@ w3lib>=1.19.0<2.0.0 django-admin-ip-restrictor==2.1.0 notifications-python-client==5.3.* pillow>=6.2.0 # for security fix. check compatibility on next wagtail upgrade +pycountry==19.8.18 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1837b9f9..922209dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -56,6 +56,7 @@ notifications-python-client==5.3.0 oauthlib==3.1.0 # via requests-oauthlib pillow==6.2.1 psycopg2==2.7.3.2 +pycountry==19.8.18 pyjwt==1.7.1 # via notifications-python-client pyrsistent==0.15.6 # via jsonschema python-dateutil==2.6.1 # via botocore diff --git a/requirements_test.txt b/requirements_test.txt index ac1c7cb2..0f29550f 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -71,6 +71,7 @@ pluggy==0.12.0 # via pytest psycopg2==2.7.3.2 py==1.7.0 # via pytest pycodestyle==2.4.0 # via flake8 +pycountry==19.8.18 pyflakes==2.0.0 # via flake8 pyjwt==1.7.1 # via notifications-python-client pyparsing==2.3.0 # via packaging diff --git a/tests/export_readiness/factories.py b/tests/export_readiness/factories.py index 1d4cfdd8..68902149 100644 --- a/tests/export_readiness/factories.py +++ b/tests/export_readiness/factories.py @@ -326,7 +326,7 @@ class Meta: fact_sheet_column_2_teaser = factory.fuzzy.FuzzyText(length=10) fact_sheet_column_2_body = factory.fuzzy.FuzzyText(length=10) - help_market_guide_cta_link = factory.fuzzy.FuzzyText(length=10) + duties_and_custom_procedures_cta_link = 'http://www.example.com' related_page_one = factory.SubFactory(ArticlePageFactory) related_page_two = factory.SubFactory(CampaignPageFactory)