project/kiwipycon/registration/pdf.py
author Madhusudan.C.S <madhusudancs@gmail.com>
Fri, 30 Oct 2009 15:09:12 +0530
changeset 1 fda1c66b25f9
permissions -rw-r--r--
Added all the files from kiwipycon and the changes made for SciPy.in.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     1
import os
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     2
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     3
from django.conf import settings
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     4
from django.template.loader import render_to_string
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     5
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     6
def save_invoice(user, registration, template_name):
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     7
    content = render_to_string(template_name,
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     8
        {'registration' : registration, 'user': user})
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
     9
    filename = '%s.html' % registration.slug
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    10
    filepath = os.path.join(settings.USER_MEDIA_PDF, filename)
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    11
    save_to_file(content, filepath)
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    12
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    13
def save_to_pdf(content, filepath):
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    14
    import pisa
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    15
    pisa.CreatePDF(str(content), file(filepath, 'wb'))
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    16
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    17
def save_to_file(content, filepath):
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    18
    fout = file(filepath, 'wb')
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    19
    fout.write(content)
fda1c66b25f9 Added all the files from kiwipycon and the changes made for SciPy.in.
Madhusudan.C.S <madhusudancs@gmail.com>
parents:
diff changeset
    20
    fout.close()