Files
notifications-admin/app/template_previews.py
Chris Hill-Scott 36db0ad598 Show all pages of a letter in the app
In research we’ve seen two problems with the click-to-see-PDF thing:

- it’s not very intuitive that the letter is clickable, or what you
  can expect when clicking the letter
- people get lost of stuck in the PDF view because it opens in the same
  tab, or they open it in a new tab and then get find their way back, or
  …

So this commit changes the show template page to show the entire
contents of the letter, same as we do for emails and text messages.

Right now it only does it on the view template page. I think we’ll have
to work out a way of showing some kind of truncated version on the _Send
yourself a test_ and _Preview_ pages. But that’s for later.
2017-04-20 15:57:43 +01:00

34 lines
1.0 KiB
Python

from flask import current_app
import requests
from app import current_service
class TemplatePreview:
@classmethod
def from_database_object(cls, template, filetype, values=None, page=None):
data = {
'letter_contact_block': current_service['letter_contact_block'],
'template': template,
'values': values
}
resp = requests.post(
'{}/preview.{}{}'.format(
current_app.config['TEMPLATE_PREVIEW_API_HOST'],
filetype,
'?page={}'.format(page) if page else '',
),
json=data,
headers={'Authorization': 'Token {}'.format(current_app.config['TEMPLATE_PREVIEW_API_KEY'])}
)
return (resp.content, resp.status_code, resp.headers.items())
@classmethod
def from_utils_template(cls, template, filetype, page=None):
return cls.from_database_object(
template._template,
filetype,
template.values,
page=page,
)