Show letter branding preview when selecting a brand

This adds a preview pane which is visible when updating a letter brand.

If JavaScript is enabled, the preview pane shows on the set-letter-branding
page, and submitting the form saves updates the letter brand for a service
immediately. If Javascript is not enabled, there is a separate 'Preview email
branding' page which shows a preview of the brand and has a 'Save' button on it.
This commit is contained in:
Katie Smith
2019-02-15 14:47:39 +00:00
parent 44781e3b69
commit d904c7e5c5
12 changed files with 297 additions and 11 deletions

View File

@@ -24,6 +24,21 @@ class TemplatePreview:
)
return (resp.content, resp.status_code, resp.headers.items())
@classmethod
def from_example_template(cls, template, filename):
data = {
'letter_contact_block': template.get('reply_to_text'),
'template': template,
'values': None,
'filename': filename
}
resp = requests.post(
'{}/preview.png'.format(current_app.config['TEMPLATE_PREVIEW_API_HOST']),
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(