Add a link to download a PDF of a sent letter

This is useful for service teams to keep a copy for their records. The
letter won’t be available in Notify once the 7 day retention period has
passed.
This commit is contained in:
Chris Hill-Scott
2017-11-13 12:17:16 +00:00
parent 03447c10da
commit 23a1c388f3
3 changed files with 79 additions and 16 deletions
+11 -5
View File
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from flask import (
abort,
render_template,
jsonify,
request,
@@ -51,9 +52,10 @@ def view_notification(service_id, notification_id):
notification['template'],
current_service,
letter_preview_url=url_for(
'.view_letter_notification_as_image',
'.view_letter_notification_as_preview',
service_id=service_id,
notification_id=notification_id,
filetype='png',
),
show_recipient=True,
redact_missing_personalisation=True,
@@ -87,10 +89,13 @@ def view_notification(service_id, notification_id):
)
@main.route("/services/<service_id>/notification/<uuid:notification_id>.png")
@main.route("/services/<service_id>/notification/<uuid:notification_id>.<filetype>")
@login_required
@user_has_permissions('view_activity', admin_override=True)
def view_letter_notification_as_image(service_id, notification_id):
def view_letter_notification_as_preview(service_id, notification_id, filetype):
if filetype not in ('pdf', 'png'):
abort(404)
notification = notification_api_client.get_notification(service_id, notification_id)
@@ -98,15 +103,16 @@ def view_letter_notification_as_image(service_id, notification_id):
notification['template'],
current_service,
letter_preview_url=url_for(
'.view_letter_notification_as_image',
'.view_letter_notification_as_preview',
service_id=service_id,
notification_id=notification_id,
filetype='png',
),
)
template.values = notification['personalisation']
return TemplatePreview.from_utils_template(template, 'png', page=request.args.get('page'))
return TemplatePreview.from_utils_template(template, filetype, page=request.args.get('page'))
@main.route("/services/<service_id>/notification/<notification_id>.json")
@@ -34,6 +34,9 @@
<p>
Estimated delivery date: {{ estimated_letter_delivery_date|string|format_date_short }}
</p>
<p class="bottom-gutter">
<a href="{{ url_for('main.view_letter_notification_as_preview', service_id=current_service.id, notification_id=notification_id, filetype='pdf') }}" download="download">Download as a PDF</a>
</p>
{% endif %}
{{ template|string }}