Skip to content

Commit

Permalink
Merge pull request #1114 from uktrade/develop
Browse files Browse the repository at this point in the history
UAT/Production release
  • Loading branch information
Miriam Forner authored Jul 21, 2023
2 parents 4b801fa + 6cbd6b5 commit b7dcc91
Show file tree
Hide file tree
Showing 76 changed files with 4,589 additions and 3,360 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,5 @@ package-lock.json
media
conf/.env
conf/env/secrets-do-not-commit

.pii-secret-hook/file_content/pii-secret-log
24 changes: 12 additions & 12 deletions components/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Generated by Django 1.11.15 on 2018-10-24 11:54
from __future__ import unicode_literals

import core.model_fields
import wagtailmarkdown.fields
import core.models
import core.validators
from django.db import migrations, models
Expand All @@ -23,17 +23,17 @@ class Migration(migrations.Migration):
fields=[
('page_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='wagtailcore.Page')),
('service_name', models.CharField(choices=[('FIND_A_SUPPLIER', 'Find a Supplier'), ('EXPORT_READINESS', 'Export Readiness'), ('INVEST', 'Invest'), ('COMPONENTS', 'Components')], db_index=True, max_length=100, null=True)),
('banner_content', core.model_fields.MarkdownField(validators=[core.validators.slug_hyperlinks])),
('banner_content_en_gb', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_de', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_ja', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_ru', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_zh_hans', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_fr', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_es', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_pt', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_pt_br', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_ar', core.model_fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content', wagtailmarkdown.fields.MarkdownField(validators=[core.validators.slug_hyperlinks])),
('banner_content_en_gb', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_de', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_ja', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_ru', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_zh_hans', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_fr', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_es', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_pt', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_pt_br', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_content_ar', wagtailmarkdown.fields.MarkdownField(null=True, validators=[core.validators.slug_hyperlinks])),
('banner_label', models.CharField(blank=True, max_length=50, null=True)),
('banner_label_en_gb', models.CharField(blank=True, max_length=50, null=True)),
('banner_label_de', models.CharField(blank=True, max_length=50, null=True)),
Expand Down
20 changes: 10 additions & 10 deletions components/migrations/0005_auto_20190823_1036.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Generated by Django 2.2.4 on 2019-08-23 10:36

import core.model_fields
import wagtailmarkdown.fields
from django.db import migrations


Expand All @@ -14,46 +14,46 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='bannercomponent',
name='banner_content',
field=core.model_fields.MarkdownField(),
field=wagtailmarkdown.fields.MarkdownField(),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_ar',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_de',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_en_gb',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_es',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_fr',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_ja',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_pt',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_zh_hans',
field=core.model_fields.MarkdownField(null=True),
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
]
58 changes: 58 additions & 0 deletions components/migrations/0006_use_new_markdown_field.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated by Django 4.1.9 on 2023-07-20 09:07

from django.db import migrations
import wagtailmarkdown.fields


class Migration(migrations.Migration):
dependencies = [
('components', '0005_auto_20190823_1036'),
]

operations = [
migrations.AlterField(
model_name='bannercomponent',
name='banner_content',
field=wagtailmarkdown.fields.MarkdownField(),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_ar',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_de',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_en_gb',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_es',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_fr',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_ja',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_pt',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
migrations.AlterField(
model_name='bannercomponent',
name='banner_content_zh_hans',
field=wagtailmarkdown.fields.MarkdownField(null=True),
),
]
19 changes: 7 additions & 12 deletions components/models.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
from django.db import models
from directory_constants import cms
from core.models import (
BasePage,
ExclusivePageMixin,
ServiceMixin,
)
from wagtail.admin.panels import (
FieldPanel, MultiFieldPanel
)
from core.mixins import ServiceNameUniqueSlugMixin
from django.db import models
from wagtail.admin.panels import FieldPanel, MultiFieldPanel
from wagtailmarkdown.fields import MarkdownField

from core.helpers import make_translated_interface
from core.model_fields import MarkdownField
from core.mixins import ServiceNameUniqueSlugMixin
from core.models import BasePage, ExclusivePageMixin, ServiceMixin


class BaseComponentsPage(ServiceNameUniqueSlugMixin, BasePage):
Expand Down Expand Up @@ -40,7 +35,7 @@ class BannerComponent(BaseComponentsPage):
children=[
FieldPanel('banner_label'),
FieldPanel('banner_content'),
]
],
),
]

Expand Down
8 changes: 4 additions & 4 deletions conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import os

import dj_database_url
from django.urls import reverse_lazy
import environ
import sentry_sdk
from django.urls import reverse_lazy
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.django import DjangoIntegration


env = environ.Env()
for env_file in env.list('ENV_FILES', default=[]):
env.read_env(os.path.join(os.path.dirname(__file__), f'env/{env_file}'))
Expand Down Expand Up @@ -91,6 +90,7 @@
'authbroker_client',
'django_celery_beat',
'drf_spectacular',
'wagtailmarkdown',
]

MIDDLEWARE = [
Expand Down Expand Up @@ -385,7 +385,7 @@
# so using an invalid default here to prevent breakages locally / in tests
GOVNOTIFY_API_KEY = env.str(
'GOVNOTIFY_API_KEY',
'directory_cms_invalid-03185ee5-578c-4ffc-8774-2288e7b34e63-e82262ea-ae8c-4c6d-8570-c16afdc8347f', # noqa
'directory_cms_invalid-03185ee5-578c-4ffc-8774-2288e7b34e63-e82262ea-ae8c-4c6d-8570-c16afdc8347f', # noqa /PS-IGNORE
)
GOVNOTIFY_REPLY_TO_EMAIL_ID = env.str('GOVNOTIFY_REPLY_TO_EMAIL_ID', '')
GOVNOTIFY_USER_PENDING_APPROVAL_TEMPLATE_ID = env.str('GOVNOTIFY_USER_PENDING_APPROVAL_TEMPLATE_ID', '')
Expand Down Expand Up @@ -432,7 +432,7 @@

REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_spectacular.openapi.AutoSchema',
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',)
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
}

if FEATURE_FLAGS['DEBUG_TOOLBAR_ON']:
Expand Down
79 changes: 30 additions & 49 deletions core/helpers.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
from num2words import num2words
import copy
import os
from urllib.parse import urljoin

import bleach
import markdown

from bleach_whitelist import markdown_tags, markdown_attrs
from modeltranslation.utils import build_localized_fieldname
from wagtail.admin.panels import ObjectList, TabbedInterface
from wagtail import hooks
from wagtail.models import Page
from wagtail.documents.models import Document
from wagtail.images.models import Image

from bleach_whitelist import markdown_attrs, markdown_tags
from django.conf import settings
from django.core.files.storage import default_storage
from django.core.files.images import get_image_dimensions
from django.core.files.storage import default_storage
from django.http import JsonResponse
from django.urls import Resolver404, resolve
from django.utils.safestring import mark_safe
from django.utils.translation import trans_real
from django.urls import resolve, Resolver404
from modeltranslation.utils import build_localized_fieldname
from num2words import num2words
from wagtail import hooks
from wagtail.admin.panels import ObjectList, TabbedInterface
from wagtail.documents.models import Document
from wagtail.images.models import Image
from wagtail.models import Page

from core import permissions

Expand Down Expand Up @@ -51,37 +49,20 @@ def translate_panel(panel, language_code):

panel = copy.deepcopy(panel)
if hasattr(panel, 'field_name'):
panel.field_name = build_localized_fieldname(
field_name=panel.field_name, lang=language_code
)
panel.field_name = build_localized_fieldname(field_name=panel.field_name, lang=language_code)
if hasattr(panel, 'relation_name'):
panel.relation_name = build_localized_fieldname(
field_name=panel.relation_name, lang=language_code
)
panel.relation_name = build_localized_fieldname(field_name=panel.relation_name, lang=language_code)
if hasattr(panel, 'children'):
panel.children = [
translate_panel(child, language_code) for child in panel.children
]
panel.children = [translate_panel(child, language_code) for child in panel.children]
return panel


def make_translated_interface(
content_panels, settings_panels=None, other_panels=None
):
def make_translated_interface(content_panels, settings_panels=None, other_panels=None):
panels = []
for code, name in settings.LANGUAGES:
panels.append(
ObjectList(
[translate_panel(panel, code) for panel in content_panels],
heading=name
)
)
panels.append(ObjectList([translate_panel(panel, code) for panel in content_panels], heading=name))
if settings_panels:
panels.append(
ObjectList(
settings_panels, classname='settings', heading='Settings'
)
)
panels.append(ObjectList(settings_panels, classname='settings', heading='Settings'))
if other_panels:
panels += other_panels
return TabbedInterface(panels)
Expand Down Expand Up @@ -154,15 +135,16 @@ def to_form(index, item):
defaults.update(item)
return defaults

data_dict = {str(index): to_form(index, item)
for index, item in enumerate(items)}
data_dict = {str(index): to_form(index, item) for index, item in enumerate(items)}

data_dict.update({
'TOTAL_FORMS': str(len(data_dict)),
'INITIAL_FORMS': str(initial),
'MIN_NUM_FORMS': str(min),
'MAX_NUM_FORMS': str(max),
})
data_dict.update(
{
'TOTAL_FORMS': str(len(data_dict)),
'INITIAL_FORMS': str(initial),
'MIN_NUM_FORMS': str(min),
'MAX_NUM_FORMS': str(max),
}
)
return data_dict


Expand All @@ -172,6 +154,7 @@ def replace_hook(hook_name, original_fn):
def inner(fn):
hooks.register('register_page_listing_buttons', fn)
return fn

return inner


Expand All @@ -191,7 +174,7 @@ def render_markdown(text, context=None):
'tables',
'smarty',
],
output_format='html5'
output_format='html5',
)
sanitised_html = bleach.clean(
html,
Expand All @@ -201,7 +184,7 @@ def render_markdown(text, context=None):
return mark_safe(sanitised_html)


class LinkPattern(markdown.inlinepatterns.LinkPattern):
class LinkPattern(markdown.inlinepatterns.LinkInlineProcessor):
def sanitize_url(self, url):
if url.startswith('slug:'):
slug = url.split(':')[1]
Expand All @@ -212,13 +195,11 @@ def sanitize_url(self, url):

class LinkerExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals):
md.inlinePatterns['link'] = LinkPattern(
markdown.inlinepatterns.LINK_RE, md
)
md.inlinePatterns['link'] = LinkPattern(markdown.inlinepatterns.LINK_RE, md)


def get_page_full_url(domain, full_path):
""" Urljoin quirkiness
"""Urljoin quirkiness
urljoin('http://great.gov.uk/international/', 'test/')
http://great.gov.uk/international/test/
Expand Down
Loading

0 comments on commit b7dcc91

Please sign in to comment.