mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
Revert "Letter preview use api not template preview"
This commit is contained in:
@@ -1,6 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import base64
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
from flask import (
|
||||
@@ -13,7 +11,6 @@ from flask import (
|
||||
url_for,
|
||||
)
|
||||
from flask_login import login_required
|
||||
from notifications_python_client.errors import APIError
|
||||
|
||||
from app import (
|
||||
current_service,
|
||||
@@ -22,7 +19,7 @@ from app import (
|
||||
notification_api_client,
|
||||
)
|
||||
from app.main import main
|
||||
from app.template_previews import get_page_count_for_letter
|
||||
from app.template_previews import TemplatePreview, get_page_count_for_letter
|
||||
from app.utils import (
|
||||
DELIVERED_STATUSES,
|
||||
FAILURE_STATUSES,
|
||||
@@ -86,12 +83,6 @@ def view_notification(service_id, notification_id):
|
||||
)
|
||||
|
||||
|
||||
def get_preview_error_image():
|
||||
path = os.path.join(os.path.dirname(__file__), "..", "..", "assets", "images", "preview_error.png")
|
||||
with open(path, "rb") as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/notification/<uuid:notification_id>.<filetype>")
|
||||
@login_required
|
||||
@user_has_permissions('view_activity')
|
||||
@@ -100,19 +91,23 @@ def view_letter_notification_as_preview(service_id, notification_id, filetype):
|
||||
if filetype not in ('pdf', 'png'):
|
||||
abort(404)
|
||||
|
||||
try:
|
||||
preview = notification_api_client.get_notification_letter_preview(
|
||||
service_id,
|
||||
notification_id,
|
||||
filetype,
|
||||
page=request.args.get('page')
|
||||
)
|
||||
notification = notification_api_client.get_notification(service_id, notification_id)
|
||||
notification['template'].update({'reply_to_text': notification['reply_to_text']})
|
||||
|
||||
display_file = base64.b64decode(preview['content'])
|
||||
except APIError:
|
||||
display_file = get_preview_error_image()
|
||||
template = get_template(
|
||||
notification['template'],
|
||||
current_service,
|
||||
letter_preview_url=url_for(
|
||||
'.view_letter_notification_as_preview',
|
||||
service_id=service_id,
|
||||
notification_id=notification_id,
|
||||
filetype='png',
|
||||
),
|
||||
)
|
||||
|
||||
return display_file
|
||||
template.values = notification['personalisation']
|
||||
|
||||
return TemplatePreview.from_utils_template(template, filetype, page=request.args.get('page'))
|
||||
|
||||
|
||||
@main.route("/services/<service_id>/notification/<notification_id>.json")
|
||||
|
||||
Reference in New Issue
Block a user