Merge pull request #1237 from alphagov/multi-page-previews

Show all pages of a letter in the app
This commit is contained in:
Chris Hill-Scott
2017-04-25 15:33:22 +01:00
committed by GitHub
5 changed files with 60 additions and 16 deletions

View File

@@ -6,7 +6,7 @@ from app import current_service
class TemplatePreview:
@classmethod
def from_database_object(cls, template, filetype, values=None):
def from_database_object(cls, template, filetype, values=None, page=None):
data = {
'letter_contact_block': current_service['letter_contact_block'],
'template': template,
@@ -14,16 +14,21 @@ class TemplatePreview:
'dvla_org_id': current_service['dvla_organisation'],
}
resp = requests.post(
'{}/preview.{}'.format(current_app.config['TEMPLATE_PREVIEW_API_HOST'], filetype),
'{}/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):
def from_utils_template(cls, template, filetype, page=None):
return cls.from_database_object(
template._template,
filetype,
template.values
template.values,
page=page,
)