From e0b61e3d704aadf776f8c8e58511f47934ae5ae3 Mon Sep 17 00:00:00 2001 From: Pea Tyczynska Date: Thu, 4 Apr 2019 12:05:17 +0100 Subject: [PATCH] Call precompiled letter preview with overlay --- app/main/views/notifications.py | 27 +++++++++++++------- app/notify_client/notification_api_client.py | 11 ++++++++ 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/main/views/notifications.py b/app/main/views/notifications.py index 3e031c632..00765ebbb 100644 --- a/app/main/views/notifications.py +++ b/app/main/views/notifications.py @@ -60,7 +60,9 @@ def view_notification(service_id, notification_id): if notification['template']['is_precompiled_letter']: try: - file_contents = view_letter_notification_as_preview(service_id, notification_id, "pdf") + file_contents = view_letter_notification_as_preview( + service_id, notification_id, "pdf" + ) page_count = pdf_page_count(io.BytesIO(file_contents)) except PdfReadError: return render_template( @@ -72,7 +74,6 @@ def view_notification(service_id, notification_id): if notification.get('postage'): notification['template']['postage'] = notification['postage'] - template = get_template( notification['template'], current_service, @@ -173,14 +174,22 @@ 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, str(notification_id)) try: - preview = notification_api_client.get_notification_letter_preview( - service_id, - notification_id, - filetype, - page=request.args.get('page') - ) + if notification['status'] == "validation-failed": + preview = notification_api_client.get_notification_letter_preview_with_overlay( + service_id, + notification_id, + filetype, + page=request.args.get('page') + ) + else: + preview = notification_api_client.get_notification_letter_preview( + service_id, + notification_id, + filetype, + page=request.args.get('page') + ) display_file = base64.b64decode(preview['content']) except APIError: diff --git a/app/notify_client/notification_api_client.py b/app/notify_client/notification_api_client.py index 579c93860..50d483ee9 100644 --- a/app/notify_client/notification_api_client.py +++ b/app/notify_client/notification_api_client.py @@ -94,6 +94,17 @@ class NotificationApiClient(NotifyAdminAPIClient): return self.get(url=get_url) + def get_notification_letter_preview_with_overlay(self, service_id, notification_id, file_type, page=None): + get_url = '/service/{}/template/preview/{}/{}{}{}'.format( + service_id, + notification_id, + file_type, + '?overlay=1', + '&page={}'.format(page) if page else '', + ) + + return self.get(url=get_url) + def update_notification_to_cancelled(self, service_id, notification_id): return self.post( url='/service/{}/notifications/{}/cancel'.format(service_id, notification_id),