Updated so that a precompiled pdf page count can be passed to the

rendering template. Currently it uses the template from the API to
calculate this which for a precompiled template is always 1.

Gets the PDF and then uses the utils method to get the page count.

* Added logic for precompiled letters
* Added test to test the new path
* Updated existing tests now the path has changed
This commit is contained in:
Richard Chapman
2018-03-08 17:10:34 +00:00
parent 60a79131e6
commit e25c6cd3b9
2 changed files with 53 additions and 1 deletions

View File

@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import base64
import io
import os
from datetime import datetime
@@ -14,6 +15,7 @@ from flask import (
)
from flask_login import login_required
from notifications_python_client.errors import APIError
from notifications_utils.pdf import pdf_page_count
from app import (
current_service,
@@ -44,6 +46,13 @@ def view_notification(service_id, notification_id):
notification = notification_api_client.get_notification(service_id, str(notification_id))
notification['template'].update({'reply_to_text': notification['reply_to_text']})
file_contents = view_letter_notification_as_preview(service_id, notification_id, "pdf")
if notification['template']['is_precompiled_letter']:
page_count = pdf_page_count(io.BytesIO(file_contents))
else:
page_count = get_page_count_for_letter(notification['template'])
template = get_template(
notification['template'],
current_service,
@@ -53,7 +62,7 @@ def view_notification(service_id, notification_id):
notification_id=notification_id,
filetype='png',
),
page_count=get_page_count_for_letter(notification['template']),
page_count=page_count,
show_recipient=True,
redact_missing_personalisation=True,
)