remove pdf/png code from admin app entirely

while PDFs work on paas, they only do that because it turns out the
python buildpack happens to have imagemagick preinstalled - if that
ever changes then it'd break. so move those to the template preview
service. This also means we can get rid of weazyprint and wand
dependencies
This commit is contained in:
Leo Hemsted
2017-04-10 17:25:08 +01:00
parent 64d162d96e
commit a6318f2674
5 changed files with 42 additions and 113 deletions

View File

@@ -1,17 +1,29 @@
from flask import current_app, current_service
from flask import current_app
import requests
from app import current_service
def get_template_preview(template, filetype):
data = {
"letter_contact_block": current_service['letter_contact_block'],
"admin_base_url": current_app.config['ADMIN_BASE_URL'],
"template": template,
"values": None
}
resp = requests.post(
'{}/preview.{}'.format(current_app.config['TEMPLATE_PREVIEW_SERVICE_URL'], filetype),
json=data,
headers={'Authorization': 'Token my-secret-key'}
)
return (resp.content, resp.status_code, resp.headers.items())
class TemplatePreview:
@classmethod
def from_database_object(cls, template, filetype, values=None):
data = {
"letter_contact_block": current_service['letter_contact_block'],
"admin_base_url": current_app.config['ADMIN_BASE_URL'],
"template": template,
"values": values
}
resp = requests.post(
'{}/preview.{}'.format(current_app.config['TEMPLATE_PREVIEW_SERVICE_URL'], filetype),
json=data,
headers={'Authorization': 'Token my-secret-key'}
)
return (resp.content, resp.status_code, resp.headers.items())
@classmethod
def from_utils_template(cls, template, filetype):
return cls.from_database_object(
template._template,
filetype,
template.values
)