project/kiwipycon/registration/pdf.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Tue, 13 Jul 2010 16:32:29 +0530
changeset 104 06b7e950a798
parent 1 fda1c66b25f9
permissions -rw-r--r--
Changed the URLs to work for 2009 site.

import os

from django.conf import settings
from django.template.loader import render_to_string

def save_invoice(user, registration, template_name):
    content = render_to_string(template_name,
        {'registration' : registration, 'user': user})
    filename = '%s.html' % registration.slug
    filepath = os.path.join(settings.USER_MEDIA_PDF, filename)
    save_to_file(content, filepath)

def save_to_pdf(content, filepath):
    import pisa
    pisa.CreatePDF(str(content), file(filepath, 'wb'))

def save_to_file(content, filepath):
    fout = file(filepath, 'wb')
    fout.write(content)
    fout.close()