Skip to content

Commit

Permalink
Merge pull request #785 from uktrade/release
Browse files Browse the repository at this point in the history
Production release
  • Loading branch information
richtier authored Feb 7, 2020
2 parents 3b2eb22 + 9895f05 commit a8b8181
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 61 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## Pre-release

### Implemented enhancements
- XOT-1275 - Add MADB link field to country guide

### Fixed bugs
No ticket - Fix error on opportunity page

## [2020.01.31](https://github.com/uktrade/directory-cms/releases/tag/2020.01.31)
[Full Changelog](https://github.com/uktrade/directory-cms/compare/2020.01.29...2020.01.31)

### Implemented enhancements

- XOT-1285 madb content markdown field
Expand Down
52 changes: 52 additions & 0 deletions export_readiness/migrations/0073_auto_20200203_1333.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# 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}')
except AttributeError:
logger.warn(f'skipping {guide.title}')
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)
]
5 changes: 3 additions & 2 deletions export_readiness/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion export_readiness/panels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion export_readiness/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 1 addition & 3 deletions great_international/models/capital_invest.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,7 @@ class CapitalInvestRelatedSubSectors(Orderable, RelatedSubSector):
)


class CapitalInvestOpportunityPage(
panels.CapitalInvestOpportunityPagePanels, BaseInternationalPage
):
class CapitalInvestOpportunityPage(panels.CapitalInvestOpportunityPagePanels, BaseInternationalPage):

parent_page_types = [
'great_international.CapitalInvestOpportunityListingPage'
Expand Down
43 changes: 30 additions & 13 deletions great_international/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import random

from directory_constants import cms
from rest_framework import serializers
from wagtail.images.api import fields as wagtail_fields
Expand Down Expand Up @@ -1637,23 +1639,38 @@ def get_sub_sectors(self, instance):
related_opportunities = serializers.SerializerMethodField()

def get_related_opportunities(self, instance):
random_sector = instance.related_sectors.order_by('?').first()
related_sectors_ids = instance.related_sectors.values_list('related_sector_id', flat=True)

if not related_sectors_ids:
return []

if random_sector:
random_sector_id = random.choice(related_sectors_ids)

three_random_opps = CapitalInvestOpportunityPage.objects.filter(
related_sectors__related_sector_id=random_sector.related_sector_id
).order_by('?').exclude(id=instance.id)[:3]
related_opps_ids = CapitalInvestOpportunityPage.objects.filter(
related_sectors__related_sector_id=random_sector_id
).exclude(id=instance.id).values_list('pk', flat=True)

serializer = RelatedCapitalInvestOpportunityPageSerializer(
three_random_opps,
many=True,
allow_null=True,
context=self.context
)
return serializer.data
if not related_opps_ids:
return []

elif len(related_opps_ids) > 3:
random_ids = random.sample(list(related_opps_ids), 3)

else:
random_ids = related_opps_ids

return []
related_opps = []

for id in random_ids:
related_opps.append(CapitalInvestOpportunityPage.objects.get(pk=id))

serializer = RelatedCapitalInvestOpportunityPageSerializer(
related_opps,
many=True,
allow_null=True,
context=self.context
)
return serializer.data


class MinimalPageSerializer(BasePageSerializer):
Expand Down
1 change: 1 addition & 0 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/export_readiness/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 8 additions & 0 deletions tests/great_international/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,14 @@ class Meta:
parent = None


class CapitalInvestRelatedSectorsFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.capital_invest.CapitalInvestRelatedSectors

page = None
related_sector = None


class CapitalInvestOpportunityListingPageFactory(
wagtail_factories.PageFactory
):
Expand Down
Loading

0 comments on commit a8b8181

Please sign in to comment.