Add remaining endpoints for PDFs and PNGs

Right now we can show what a letter template looks like as a PDF or PNG.

This commit completes the work so this is also possible when:

- showing a template with the placeholders replaced
- showing any version of a template

Also removes dependency on `Exception().message`, which was deprecated
in Python 2.6. See
97f82d565f
for full details.
This commit is contained in:
Chris Hill-Scott
2016-12-20 14:38:34 +00:00
parent a159f351a8
commit 559433c5d2
8 changed files with 214 additions and 33 deletions

View File

@@ -12,6 +12,7 @@ from notifications_utils.template import (
SMSPreviewTemplate,
EmailPreviewTemplate,
LetterPDFLinkTemplate,
LetterPreviewTemplate,
)
import pyexcel
@@ -224,7 +225,13 @@ def is_gov_user(email_address):
return bool(re.search(email_regex, email_address.lower()))
def get_template(template, service, show_recipient=False, expand_emails=False):
def get_template(
template,
service,
show_recipient=False,
expand_emails=False,
letter_preview_url=None,
):
if 'email' == template['template_type']:
return EmailPreviewTemplate(
template,
@@ -241,7 +248,12 @@ def get_template(template, service, show_recipient=False, expand_emails=False):
show_recipient=show_recipient
)
if 'letter' == template['template_type']:
return LetterPDFLinkTemplate(
template,
service_id=service['id'],
)
if letter_preview_url:
return LetterPDFLinkTemplate(
template,
preview_url=letter_preview_url,
)
else:
return LetterPreviewTemplate(
template
)