Moved the notifications code to go to admin to get the the template

preview document rather than go to template preview.

This will remove the logic from admin and place it in api so it is
easier to expand on later when there are precompiled PDFs
This commit is contained in:
Richard Chapman
2018-02-27 15:08:39 +00:00
committed by Ken Tsang
parent 68fc6b5cb4
commit c4f0b4d35d
2 changed files with 25 additions and 1 deletions

View File

@@ -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/<service_id>/notification/<notification_id>.json")
@user_has_permissions('view_activity', admin_override=True)

View File

@@ -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)