diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index e880d6cec..c88c3c13e 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -1,4 +1,7 @@ # -*- coding: utf-8 -*- +import base64 +import json +from collections import ItemsView from datetime import datetime from flask import ( @@ -88,6 +91,8 @@ def view_notification(service_id, notification_id): @user_has_permissions('view_activity', admin_override=True) def view_letter_notification_as_preview(service_id, notification_id, filetype): + print("\n\nview_letter_notification_as_preview\n\n") + if filetype not in ('pdf', 'png'): abort(404) @@ -107,8 +112,15 @@ def view_letter_notification_as_preview(service_id, notification_id, filetype): template.values = notification['personalisation'] - return TemplatePreview.from_utils_template(template, filetype, page=request.args.get('page')) + preview = notification_api_client.get_notification_letter_preview( + service_id, + template.id, + notification_id, + filetype, + page=request.args.get('page') + ) + return base64.b64decode(preview['content']), preview['status'], ItemsView(dict(preview['headers'])) @main.route("/services//notification/.json") @user_has_permissions('view_activity', admin_override=True) diff --git a/app/notify_client/notification_api_client.py b/app/notify_client/notification_api_client.py index bb4140066..b3ddf51fd 100644 --- a/app/notify_client/notification_api_client.py +++ b/app/notify_client/notification_api_client.py @@ -78,3 +78,15 @@ class NotificationApiClient(NotifyAdminAPIClient): if notification['notification_type'] == 'letter' and notification['status'] in ('created', 'sending'): notification['status'] = 'accepted' return notifications + + def get_notification_letter_preview(self, service_id, template_id, notification_id, file_type, page=None): + + get_url = '/service/{}/template/{}/pdf-preview/{}/{}{}'.format( + service_id, + template_id, + notification_id, + file_type, + '?page={}'.format(page) if page else '' + ) + + return self.get(url=get_url)