Skip to content

Commit

Permalink
Merge pull request #1097 from uktrade/feature/KLS-736-Move-Export-Rea…
Browse files Browse the repository at this point in the history
…diness-Models

Move export_readiness models to core app
  • Loading branch information
Miriam Forner authored Jun 14, 2023
2 parents 72b2057 + 48984b6 commit 158346d
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 31 deletions.
46 changes: 46 additions & 0 deletions core/migrations/0031_region_tag_industrytag_country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Generated by Django 4.1.9 on 2023-06-14 09:39

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('wagtailimages', '0024_index_image_file_hash'),
('core', '0030_greatmedia'),
]

operations = [
migrations.CreateModel(
name='Region',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
],
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
],
),
migrations.CreateModel(
name='IndustryTag',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
('icon', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='+', to='wagtailimages.image')),
],
),
migrations.CreateModel(
name='Country',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100, unique=True)),
('slug', models.CharField(max_length=100, unique=True)),
('region', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='core.region')),
],
),
]
43 changes: 43 additions & 0 deletions core/migrations/0032_auto_20230614_0954.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Generated by Django 4.1.9 on 2023-06-14 09:54

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('core', '0031_region_tag_industrytag_country'),
]

def copy_export_readiness_data(apps, schema_editor):
ExportReadinessTag = apps.get_model("export_readiness", "Tag")
ExportReadinessIndustryTag = apps.get_model("export_readiness", "IndustryTag")
ExportReadinessRegion = apps.get_model("export_readiness", "Region")
ExportReadinessCountry = apps.get_model("export_readiness", "Country")

CoreTag = apps.get_model("core", "Tag")
CoreIndustryTag = apps.get_model("core", "IndustryTag")
CoreRegion = apps.get_model("core", "Region")
CoreCountry = apps.get_model("core", "Country")

CoreRegion.objects.bulk_create(ExportReadinessRegion.objects.all())
CoreTag.objects.bulk_create(ExportReadinessTag.objects.all())
CoreCountry.objects.bulk_create(ExportReadinessCountry.objects.all())
CoreIndustryTag.objects.bulk_create(ExportReadinessIndustryTag.objects.all())


def delete_export_readiness_data(apps, schema_editor):
Tag = apps.get_model("core", "Tag")
IndustryTag = apps.get_model("core", "IndustryTag")
Region = apps.get_model("core", "Region")
Country = apps.get_model("core", "Country")

Country.objects.all().delete()
IndustryTag.objects.all().delete()
Region.objects.all().delete()
Tag.objects.all().delete()


operations = [
migrations.RunPython(copy_export_readiness_data, delete_export_readiness_data),
]
64 changes: 64 additions & 0 deletions core/snippets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from django.db import models

from wagtail.admin.panels import FieldPanel
from wagtail.snippets.models import register_snippet


@register_snippet
class Tag(models.Model):
name = models.CharField(max_length=100, unique=True)

def __str__(self):
return self.name

panels = [
FieldPanel('name')
]


@register_snippet
class IndustryTag(models.Model):
name = models.CharField(max_length=100, unique=True)
icon = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+'
)

def __str__(self):
return self.name

panels = [
FieldPanel('name'),
FieldPanel('icon')
]


@register_snippet
class Region(models.Model):
name = models.CharField(max_length=100, unique=True)

def __str__(self):
return self.name

panels = [
FieldPanel('name')
]


@register_snippet
class Country(models.Model):
name = models.CharField(max_length=100, unique=True)
slug = models.CharField(max_length=100, unique=True)
region = models.ForeignKey(Region, null=True, blank=True, on_delete=models.SET_NULL)

def __str__(self):
return self.name

panels = [
FieldPanel('name'),
FieldPanel('slug'),
FieldPanel('region')
]
2 changes: 1 addition & 1 deletion core/upstream_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from core import helpers
from core.cache import SERVICE_NAMES_TO_ROOT_PATHS

from export_readiness.snippets import Tag
from core.snippets import Tag


class AbstractFieldSerializer(abc.ABC):
Expand Down
2 changes: 1 addition & 1 deletion great_international/models/great_international.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from core.mixins import ServiceHomepageMixin
from core.model_fields import MarkdownField
from core.models import WagtailAdminExclusivePageMixin
from export_readiness import snippets
from core import snippets
from great_international.blocks import great_international as blocks
from great_international.panels import great_international as panels
from . import find_a_supplier as fas_models
Expand Down
4 changes: 2 additions & 2 deletions requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ django-filter>=2.4.0
django-redis
celery[redis]
django-celery-beat==2.5.0
kombu==5.2.3
kombu==5.3.0
requests[security]>=2.31.0
markdown==2.*
bleach==3.*
Expand All @@ -38,4 +38,4 @@ gevent==22.10.*
psycogreen==1.0.2
wagtailmedia==0.14.*
cryptography==39.*
oauthlib==3.2.*
oauthlib==3.2.*
27 changes: 16 additions & 11 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ beautifulsoup4==4.11.2
# via
# directory-components
# wagtail
billiard==3.6.4.0
billiard==4.1.0
# via celery
bleach==3.3.1
# via -r requirements.in
Expand All @@ -32,7 +32,7 @@ botocore==1.27.96
# via
# boto3
# s3transfer
celery[redis]==5.2.7
celery[redis]==5.3.0
# via
# -r requirements.in
# django-celery-beat
Expand Down Expand Up @@ -106,7 +106,7 @@ django-health-check==3.17.0
# via directory-healthcheck
django-modelcluster==6.0
# via wagtail
django-modeltranslation==0.18.9
django-modeltranslation==0.18.10
# via
# -r requirements.in
# wagtail-modeltranslation
Expand Down Expand Up @@ -137,7 +137,9 @@ docopt==0.6.2
# num2words
draftjs-exporter==2.1.7
# via wagtail
elastic-apm==6.15.1
ecs-logging==2.0.2
# via elastic-apm
elastic-apm==6.16.2
# via -r requirements.in
et-xmlfile==1.1.0
# via openpyxl
Expand All @@ -159,7 +161,7 @@ jmespath==1.0.1
# botocore
jsonschema==3.2.0
# via directory-components
kombu==5.2.3
kombu==5.3.0
# via
# -r requirements.in
# celery
Expand Down Expand Up @@ -202,12 +204,12 @@ python-crontab==2.7.1
python-dateutil==2.8.2
# via
# botocore
# celery
# python-crontab
pytube==9.2.2
# via -r requirements.in
pytz==2023.3
# via
# celery
# django-modelcluster
# django-timezone-field
# djangorestframework
Expand All @@ -226,7 +228,7 @@ requests-oauthlib==1.3.1
# via django-staff-sso-client
s3transfer==0.6.1
# via boto3
sentry-sdk==1.24.0
sentry-sdk==1.25.1
# via -r requirements.in
sigauth==5.2.0
# via -r requirements.in
Expand All @@ -245,15 +247,18 @@ soupsieve==2.4.1
# via beautifulsoup4
sqlparse==0.4.4
# via django
telepath==0.3
telepath==0.3.1
# via wagtail
typing-extensions==4.6.2
typing-extensions==4.6.3
# via
# asgiref
# dj-database-url
# django-modeltranslation
# kombu
tzdata==2023.3
# via django-celery-beat
# via
# celery
# django-celery-beat
urllib3==1.26.16
# via
# -r requirements.in
Expand All @@ -275,7 +280,7 @@ wagtail==4.1.5
# wagtailmedia
wagtail-modeltranslation==0.13.0
# via -r requirements.in
wagtailmedia==0.14.1
wagtailmedia==0.14.2
# via -r requirements.in
wcwidth==0.2.6
# via prompt-toolkit
Expand Down
Loading

0 comments on commit 158346d

Please sign in to comment.