[reportlab-users] Cheetah

Robson, Alan alan.robson at viasat.com
Tue Feb 5 12:24:47 EST 2008


I don't know if this is the right way to do it, but I created a python module full of "helper" functions and then included it in the cheetah template.

That way I could create a function in python that took the dictionary as a parameter and returned a value that cheetah could use.

For example.

in my_module...

def to_city(my_dictionary, violator):
record = my_dictionary.get(violator, False)
if record:
return record.get('city', 'no fixed abode')
return 'no fixed abode'

then inside cheetah, something like...

#from my_module import *
...
<doc>
<para>You are from<b>$to_city($dictionary, $violator)(</b><br/><br/>


________________________________

From: reportlab-users-bounces at reportlab.com on behalf of Brandon Rich
Sent: Tue 2/5/2008 8:57 AM
To: Support list for users of Reportlab software
Subject: [reportlab-users] Cheetah



I'm not sure if this is the right forum for this question, but perhaps
someone has some insight to my question .

Currently I have a cheetah template file that has all hard coded
information that I am passing back to Reportlab and then appending to a
PDF. I also have a python file that is passed back to Reportlab in the
form of a dictionary. Question, once changing the cheetah template
file, to include say a $city, how do I pass the information from the
dictionary? I have looked at several examples online, but none seem to
be working currently. Any help would be great.

Thanks in advance

Brandon

from pdfutil import *
from StringIO import StringIO
from notice_data import *
from Cheetah.Template import Template

notices = getNotices() #returns dictionary
file = open("test.pdf","wb")
letters_file = StringIO()
create_letter(letters_file) #create_letter returns handled XML currently

pdf = letters_file.getvalue()
letters_file.close()
file.write(pdf)
file.close()

Cheetah template file

<doc>
<para>You are from<b>$city</b><br/><br/>

Dictionary
[{'violator': {'city': 'LA', 'zip': '9999', 'suffix': 'Jr'}]
_______________________________________________
reportlab-users mailing list
reportlab-users at reportlab.com
http://two.pairlist.net/mailman/listinfo/reportlab-users


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://two.pairlist.net/pipermail/reportlab-users/attachments/20080205/b483770b/attachment.html>


More information about the reportlab-users mailing list