mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-15 07:18:58 -04:00
Incorporate breaking utils changes
Brings in: - [ ] https://github.com/alphagov/notifications-utils/pull/94
This commit is contained in:
@@ -3,8 +3,7 @@ from app.main import main
|
||||
from app import convert_to_boolean
|
||||
from flask_login import (login_required, current_user)
|
||||
|
||||
|
||||
from notifications_utils.renderers import HTMLEmail
|
||||
from notifications_utils.template import HTMLEmailTemplate
|
||||
|
||||
|
||||
@main.route('/')
|
||||
@@ -57,9 +56,7 @@ def terms():
|
||||
|
||||
@main.route('/_email')
|
||||
def email_template():
|
||||
return HTMLEmail(
|
||||
govuk_banner=convert_to_boolean(request.args.get('govuk_banner', True))
|
||||
)(
|
||||
return str(HTMLEmailTemplate({'subject': 'foo', 'content': (
|
||||
'Lorem Ipsum is simply dummy text of the printing and typesetting '
|
||||
'industry.\n\nLorem Ipsum has been the industry’s standard dummy '
|
||||
'text ever since the 1500s, when an unknown printer took a galley '
|
||||
@@ -96,7 +93,8 @@ def email_template():
|
||||
'This is an example of an email sent using GOV.UK Notify.'
|
||||
'\n\n'
|
||||
'https://www.notifications.service.gov.uk'
|
||||
)
|
||||
)}, govuk_banner=convert_to_boolean(request.args.get('govuk_banner', True))
|
||||
))
|
||||
|
||||
|
||||
@main.route('/documentation')
|
||||
|
||||
@@ -16,7 +16,6 @@ from flask import (
|
||||
)
|
||||
from flask_login import login_required
|
||||
from werkzeug.datastructures import MultiDict
|
||||
from notifications_utils.template import Template
|
||||
|
||||
from app import (
|
||||
job_api_client,
|
||||
@@ -31,7 +30,8 @@ from app.utils import (
|
||||
generate_previous_dict,
|
||||
user_has_permissions,
|
||||
generate_notifications_csv,
|
||||
get_help_argument
|
||||
get_help_argument,
|
||||
get_template,
|
||||
)
|
||||
from app.statistics_utils import add_rate_to_job
|
||||
|
||||
@@ -108,14 +108,13 @@ def view_job(service_id, job_id):
|
||||
'views/jobs/job.html',
|
||||
finished=(total_notifications == processed_notifications),
|
||||
uploaded_file_name=job['original_file_name'],
|
||||
template=Template(
|
||||
template=get_template(
|
||||
service_api_client.get_service_template(
|
||||
service_id=service_id,
|
||||
template_id=job['template'],
|
||||
version=job['template_version']
|
||||
)['data'],
|
||||
prefix=current_service['name'],
|
||||
sms_sender=current_service['sms_sender']
|
||||
current_service,
|
||||
),
|
||||
status=request.args.get('status', ''),
|
||||
updates_url=url_for(
|
||||
|
||||
@@ -18,9 +18,7 @@ from flask import (
|
||||
|
||||
from flask_login import login_required, current_user
|
||||
from notifications_utils.columns import Columns
|
||||
from notifications_utils.template import Template
|
||||
from notifications_utils.recipients import RecipientCSV, first_column_headings, validate_and_format_phone_number
|
||||
from notifications_utils.renderers import EmailPreview, SMSPreview, LetterPDFLink
|
||||
|
||||
from app.main import main
|
||||
from app.main.forms import CsvUploadForm, ChooseTimeForm, get_next_days_until, get_furthest_possible_scheduled_time
|
||||
@@ -29,7 +27,7 @@ from app.main.uploader import (
|
||||
s3download
|
||||
)
|
||||
from app import job_api_client, service_api_client, current_service, user_api_client
|
||||
from app.utils import user_has_permissions, get_errors_for_csv, Spreadsheet, get_help_argument, get_renderer
|
||||
from app.utils import user_has_permissions, get_errors_for_csv, Spreadsheet, get_help_argument, get_template
|
||||
|
||||
|
||||
def get_page_headings(template_type):
|
||||
@@ -89,10 +87,8 @@ def choose_template(service_id, template_type):
|
||||
return render_template(
|
||||
'views/templates/choose.html',
|
||||
templates=[
|
||||
Template(
|
||||
template,
|
||||
renderer=get_renderer(template_type, current_service, show_recipient=False)
|
||||
) for template in service_api_client.get_service_templates(service_id)['data']
|
||||
get_template(template, current_service)
|
||||
for template in service_api_client.get_service_templates(service_id)['data']
|
||||
if template['template_type'] == template_type
|
||||
],
|
||||
template_type=template_type,
|
||||
@@ -104,10 +100,12 @@ def choose_template(service_id, template_type):
|
||||
@login_required
|
||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters')
|
||||
def send_messages(service_id, template_id):
|
||||
template = Template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data']
|
||||
|
||||
template = get_template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'],
|
||||
current_service,
|
||||
show_recipient=True
|
||||
)
|
||||
template.renderer = get_renderer(template.template_type, current_service, show_recipient=True)
|
||||
|
||||
form = CsvUploadForm()
|
||||
if form.validate_on_submit():
|
||||
@@ -145,7 +143,9 @@ def send_messages(service_id, template_id):
|
||||
@login_required
|
||||
@user_has_permissions('send_texts', 'send_emails', 'send_letters', 'manage_templates', any_=True)
|
||||
def get_example_csv(service_id, template_id):
|
||||
template = Template(service_api_client.get_service_template(service_id, template_id)['data'])
|
||||
template = get_template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'], current_service
|
||||
)
|
||||
return Spreadsheet.from_rows([
|
||||
first_column_headings[template.template_type] + list(template.placeholders),
|
||||
get_example_csv_rows(template)
|
||||
@@ -162,14 +162,12 @@ def send_test(service_id, template_id):
|
||||
|
||||
file_name = current_app.config['TEST_MESSAGE_FILENAME']
|
||||
|
||||
template = Template(
|
||||
template = get_template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'],
|
||||
prefix=current_service['name'],
|
||||
sms_sender=current_service['sms_sender']
|
||||
current_service,
|
||||
show_recipient=True
|
||||
)
|
||||
|
||||
template.renderer = get_renderer(template.template_type, current_service, show_recipient=True)
|
||||
|
||||
if len(template.placeholders) == 0 or request.method == 'POST':
|
||||
upload_id = s3upload(
|
||||
service_id,
|
||||
@@ -209,10 +207,8 @@ def send_test(service_id, template_id):
|
||||
def send_from_api(service_id, template_id):
|
||||
return render_template(
|
||||
'views/send-from-api.html',
|
||||
template=Template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'],
|
||||
prefix=current_service['name'],
|
||||
sms_sender=current_service['sms_sender']
|
||||
template=get_template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'], current_service
|
||||
)
|
||||
)
|
||||
|
||||
@@ -234,15 +230,15 @@ def check_messages(service_id, template_type, upload_id):
|
||||
if not contents:
|
||||
flash('There was a problem reading your upload file')
|
||||
|
||||
template = Template(
|
||||
template = get_template(
|
||||
service_api_client.get_service_template(
|
||||
service_id,
|
||||
session['upload_data'].get('template_id')
|
||||
)['data']
|
||||
)['data'],
|
||||
current_service,
|
||||
show_recipient=True
|
||||
)
|
||||
|
||||
template.renderer = get_renderer(template_type, current_service, show_recipient=True)
|
||||
|
||||
recipients = RecipientCSV(
|
||||
contents,
|
||||
template_type=template.template_type,
|
||||
|
||||
@@ -8,13 +8,12 @@ from flask_weasyprint import HTML, render_pdf
|
||||
from dateutil.parser import parse
|
||||
from wand.image import Image
|
||||
|
||||
from notifications_utils.template import Template
|
||||
from notifications_utils.template import LetterPreviewTemplate
|
||||
from notifications_utils.recipients import first_column_headings
|
||||
from notifications_utils.renderers import LetterPreview
|
||||
from notifications_python_client.errors import HTTPError
|
||||
|
||||
from app.main import main
|
||||
from app.utils import user_has_permissions, get_renderer
|
||||
from app.utils import user_has_permissions, get_template
|
||||
from app.main.forms import SMSTemplateForm, EmailTemplateForm, LetterTemplateForm
|
||||
from app.main.views.send import get_example_csv_rows
|
||||
from app import service_api_client, current_service, template_statistics_client
|
||||
@@ -43,15 +42,13 @@ page_headings = {
|
||||
admin_override=True, any_=True
|
||||
)
|
||||
def view_template(service_id, template_id):
|
||||
template = Template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data']
|
||||
)
|
||||
template.renderer = get_renderer(
|
||||
template.template_type, current_service, show_recipient=False, expand_emails=True
|
||||
)
|
||||
return render_template(
|
||||
'views/templates/template.html',
|
||||
template=template
|
||||
template=get_template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'],
|
||||
current_service,
|
||||
expand_emails=True
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -59,11 +56,11 @@ def view_template(service_id, template_id):
|
||||
@login_required
|
||||
@user_has_permissions('view_activity', admin_override=True)
|
||||
def view_letter_template_as_pdf(service_id, template_id):
|
||||
template = Template(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'],
|
||||
renderer=LetterPreview()
|
||||
)
|
||||
return render_pdf(HTML(string=template.rendered))
|
||||
return render_pdf(HTML(string=str(
|
||||
LetterPreviewTemplate(
|
||||
service_api_client.get_service_template(service_id, template_id)['data'],
|
||||
)
|
||||
)))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/templates/<template_id>.png")
|
||||
@@ -92,15 +89,13 @@ def view_letter_template_as_image(service_id, template_id):
|
||||
any_=True
|
||||
)
|
||||
def view_template_version(service_id, template_id, version):
|
||||
template = Template(
|
||||
service_api_client.get_service_template(service_id, template_id, version)['data']
|
||||
)
|
||||
template.renderer = get_renderer(
|
||||
template.template_type, current_service, show_recipient=False, expand_emails=True
|
||||
)
|
||||
return render_template(
|
||||
'views/templates/template_history.html',
|
||||
template=template
|
||||
template=get_template(
|
||||
service_api_client.get_service_template(service_id, template_id, version)['data'],
|
||||
current_service,
|
||||
expand_emails=True
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
@@ -154,14 +149,14 @@ def edit_service_template(service_id, template_id):
|
||||
|
||||
if form.validate_on_submit():
|
||||
subject = form.subject.data if hasattr(form, 'subject') else None
|
||||
new_template = Template({
|
||||
new_template = get_template({
|
||||
'name': form.name.data,
|
||||
'content': form.template_content.data,
|
||||
'subject': subject,
|
||||
'template_type': template['template_type'],
|
||||
'id': template['id']
|
||||
})
|
||||
template_change = Template(template).compare_to(new_template)
|
||||
}, current_service)
|
||||
template_change = get_template(template, current_service).compare_to(new_template)
|
||||
if template_change.has_different_placeholders and not request.form.get('confirm'):
|
||||
return render_template(
|
||||
'views/templates/breaking-change.html',
|
||||
@@ -260,18 +255,12 @@ def delete_service_template(service_id, template_id):
|
||||
any_=True
|
||||
)
|
||||
def view_template_versions(service_id, template_id):
|
||||
|
||||
versions = []
|
||||
for template in service_api_client.get_service_template_versions(service_id, template_id)['data']:
|
||||
template = Template(template)
|
||||
template.renderer = get_renderer(
|
||||
template.template_type, current_service, show_recipient=False, expand_emails=True
|
||||
)
|
||||
versions.append(template)
|
||||
|
||||
return render_template(
|
||||
'views/templates/choose_history.html',
|
||||
versions=versions
|
||||
versions=[
|
||||
get_template(template, current_service, expand_emails=True)
|
||||
for template in service_api_client.get_service_template_versions(service_id, template_id)['data']
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user