tags:

views:

46

answers:

2

One of our page templates is made up of a bunch of macros. These items are a bunch of html tables.

Now, I want a couple of these tables in a Python script to create a PDF. Is there a way call a macro from a Python script and get back the HTML that is produced?

If so, can you explain?

Thanks Eric

A: 

I'd probably use urllib.urlopen(url), pull the data from the page back to python and use BeautifulSoup to pull the table(s) out of the HTML... And then render that to PDF with XHTML2PDF (pisa.ho).

There might be a simpler way but for me, this would be the least stressful approach.

Oli
This was my original thought too. However, I didn't want to have to worry about permissions. The data varies depending on the role of the user. That is already built in the macros.
Eric
A: 

Maybe you could create a new template including (use-macro) just the macros you want to access from python and then use z3c.pt.pagetemplate.PageTemplateFile() to render it?

Actually, it might be possible (and certainly easier) to use chameleon.zpt.template.PageTemplate('<div tal:use-macro="<your-macro-here>" />'), but I've never did this myself.

Guilherme Salgado
Thank you. This sounds promising. I will see where I get with it.
Eric