From 3204200fc21b2d0ff3b63e1d1c179474bfbde691 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Thu, 3 Oct 2019 12:58:57 +0100 Subject: [PATCH 1/3] Add GOVUK Frontend Jinja extension --- requirements-app.txt | 1 + requirements.txt | 11 ++++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/requirements-app.txt b/requirements-app.txt index 3becbe591..a650b656e 100644 --- a/requirements-app.txt +++ b/requirements-app.txt @@ -24,3 +24,4 @@ awscli-cwlogs>=1.4,<1.5 itsdangerous==0.24 # pyup: <1.0.0 git+https://github.com/alphagov/notifications-utils.git@34.1.0#egg=notifications-utils==34.1.0 +git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.3.0-alpha#egg=govuk-frontend-jinja==0.3.0-alpha diff --git a/requirements.txt b/requirements.txt index 734270dca..9f5399ffd 100644 --- a/requirements.txt +++ b/requirements.txt @@ -26,13 +26,14 @@ awscli-cwlogs>=1.4,<1.5 itsdangerous==0.24 # pyup: <1.0.0 git+https://github.com/alphagov/notifications-utils.git@34.1.0#egg=notifications-utils==34.1.0 +git+https://github.com/alphagov/govuk-frontend-jinja.git@v0.3.0-alpha#egg=govuk-frontend-jinja==0.3.0-alpha ## The following requirements were added by pip freeze: -awscli==1.16.233 +awscli==1.16.251 bleach==3.1.0 boto3==1.6.16 -botocore==1.12.223 -certifi==2019.6.16 +botocore==1.12.241 +certifi==2019.9.11 chardet==3.0.4 Click==7.0 colorama==0.3.9 @@ -70,9 +71,9 @@ six==1.12.0 smartypants==2.0.1 statsd==3.3.0 texttable==1.6.2 -urllib3==1.25.3 +urllib3==1.25.6 webencodings==0.5.1 -Werkzeug==0.15.6 +Werkzeug==0.16.0 WTForms==2.2.1 xlrd==1.2.0 xlwt==1.3.0 From 5321685a879dcfeb9969e41dd56b8b8e9fb0b890 Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Thu, 3 Oct 2019 12:59:26 +0100 Subject: [PATCH 2/3] Add GOVUK Frontend NPM module The GOVUK Frontend Jinja extension adds this as an extra location to source templates from. --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 098318c9f..b6ebd1675 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "@babel/preset-env": "7.4.2", "diff-dom": "2.5.1", "govuk-elements-sass": "3.1.2", + "govuk-frontend": "2.13.0", "govuk_frontend_toolkit": "8.1.0", "govuk_template_jinja": "0.24.1", "gulp": "4.0.0", From f6a0026d6740831fc3034f4076c607005eb3ffcf Mon Sep 17 00:00:00 2001 From: Tom Byers Date: Thu, 3 Oct 2019 13:00:32 +0100 Subject: [PATCH 3/3] Add extension initialisation in app init --- app/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/__init__.py b/app/__init__.py index 81477c346..e9f1bc698 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -7,6 +7,7 @@ from numbers import Number from time import monotonic import ago +import jinja2 from flask import ( current_app, flash, @@ -22,6 +23,7 @@ from flask.globals import _lookup_req_object, _request_ctx_stack from flask_login import LoginManager, current_user from flask_wtf import CSRFProtect from flask_wtf.csrf import CSRFError +from govuk_frontend_jinja.flask_ext import init_govuk_frontend from itsdangerous import BadSignature from notifications_python_client.errors import HTTPError from notifications_utils import formatters, logging, request_helper @@ -116,6 +118,9 @@ def create_app(application): init_app(application) + init_govuk_frontend(application) + init_jinja(application) + for client in ( # Gubbins @@ -701,3 +706,13 @@ def add_template_filters(application): id_safe, ]: application.add_template_filter(fn) + + +def init_jinja(application): + repo_root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + template_folders = [ + os.path.join(repo_root, 'app/templates'), + os.path.join(repo_root, 'node_modules/govuk-frontend'), + ] + jinja_loader = jinja2.FileSystemLoader(template_folders) + application.jinja_loader = jinja_loader