Created
August 10, 2014 05:30
-
-
Save brendanmckenzie/77b1097a49774d3d5edb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from os import unlink | |
from uuid import uuid3, NAMESPACE_DNS | |
from task_queue.app import app | |
from utils import upload, pdf, html | |
from model import Session, AgencyPdf | |
def upload_pdf(pdf_file): | |
file_name = str(uuid3(NAMESPACE_DNS, 'takeoffgo.com')) + '.pdf' | |
path = 'pdf/' + file_name | |
return upload(pdf_file, path) | |
@app.task | |
def generate_pdf(id): | |
db = Session() | |
req = db.query(AgencyPdf).get(id) | |
html_file = html.from_template(req.agencytemplate.content, req.data) | |
pdf_file = pdf.from_html(html_file) | |
url = upload_pdf(pdf_file) | |
unlink(html_file) | |
unlink(pdf_file) | |
req.url = url | |
db.commit() | |
return url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment