project/kiwipycon/registration/pdf.py
changeset 94 87e77aa18610
parent 93 e86755df35da
child 95 f94e0cd9a862
equal deleted inserted replaced
93:e86755df35da 94:87e77aa18610
     1 import os
       
     2 
       
     3 from django.conf import settings
       
     4 from django.template.loader import render_to_string
       
     5 
       
     6 def save_invoice(user, registration, template_name):
       
     7     content = render_to_string(template_name,
       
     8         {'registration' : registration, 'user': user})
       
     9     filename = '%s.html' % registration.slug
       
    10     filepath = os.path.join(settings.USER_MEDIA_PDF, filename)
       
    11     save_to_file(content, filepath)
       
    12 
       
    13 def save_to_pdf(content, filepath):
       
    14     import pisa
       
    15     pisa.CreatePDF(str(content), file(filepath, 'wb'))
       
    16 
       
    17 def save_to_file(content, filepath):
       
    18     fout = file(filepath, 'wb')
       
    19     fout.write(content)
       
    20     fout.close()