mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-02 15:38:19 -04:00
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:
committed by
Ken Tsang
parent
68fc6b5cb4
commit
c4f0b4d35d
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user