From 623da2aa87e0df114c3a23c3d8eda1b10e059c3c Mon Sep 17 00:00:00 2001 From: richtier Date: Mon, 3 Feb 2020 14:00:47 +0000 Subject: [PATCH 1/2] Add MADB link field to country guide --- CHANGELOG.md | 1 + .../migrations/0073_auto_20200203_1333.py | 50 +++++++++++++++++++ export_readiness/models.py | 5 +- export_readiness/panels.py | 2 +- export_readiness/serializers.py | 2 +- requirements.in | 1 + requirements.txt | 3 +- requirements_test.txt | 3 +- tests/export_readiness/factories.py | 2 +- 9 files changed, 62 insertions(+), 7 deletions(-) create mode 100644 export_readiness/migrations/0073_auto_20200203_1333.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 45f85a8f..686c4398 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 4a901804..52652b90 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 @@ -68,7 +69,7 @@ requests==2.21.0 s3transfer==0.1.13 # via boto3 sentry-sdk==0.13.4 sigauth==4.1.0 -six==1.13.0 # via bleach, html5lib, jsonschema, mohawk, pyrsistent, w3lib, wagtail +six==1.13.0 # via bleach, html5lib, jsonschema, mohawk, pyrsistent, python-dateutil, w3lib, wagtail sqlparse==0.3.0 # via django unidecode==1.1.1 # via wagtail urllib3==1.24.3 diff --git a/requirements_test.txt b/requirements_test.txt index 49745644..847acd9c 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 @@ -90,7 +91,7 @@ requests==2.21.0 s3transfer==0.1.13 # via boto3 sentry-sdk==0.13.4 sigauth==4.1.0 -six==1.12.0 # via bleach, faker, freezegun, html5lib, jsonschema, mohawk, more-itertools, packaging, pip-tools, pyrsistent, requests-mock, w3lib, wagtail +six==1.12.0 # via bleach, faker, freezegun, html5lib, jsonschema, mohawk, more-itertools, packaging, pip-tools, pyrsistent, python-dateutil, requests-mock, w3lib, wagtail sqlparse==0.2.4 # via django, django-debug-toolbar termcolor==1.1.0 # via pytest-sugar text-unidecode==1.2 # via faker 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) From eac5d76ee6aef249b790ed058d2eca160f1a4439 Mon Sep 17 00:00:00 2001 From: richtier Date: Mon, 3 Feb 2020 15:56:49 +0000 Subject: [PATCH 2/2] Upgrade django --- requirements.txt | 2 +- requirements_test.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 52652b90..922209dd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -31,7 +31,7 @@ django-redis==4.10.0 django-staff-sso-client==1.0.0 django-taggit==0.24.0 # via wagtail django-treebeard==4.3 # via wagtail -django==2.2.8 +django==2.2.10 django_storages==1.7.1 djangorestframework==3.9.4 docopt==0.6.2 # via notifications-python-client diff --git a/requirements_test.txt b/requirements_test.txt index 847acd9c..0f29550f 100644 --- a/requirements_test.txt +++ b/requirements_test.txt @@ -36,7 +36,7 @@ django-redis==4.10.0 django-staff-sso-client==1.0.0 django-taggit==0.23.0 # via wagtail django-treebeard==4.3 # via wagtail -django==2.2.8 +django==2.2.10 django_storages==1.7.1 djangorestframework==3.9.4 docopt==0.6.2 # via coveralls, notifications-python-client