Skip to content

ODF Templating using Appy pod

November 28, 2009

The last time I tried to produce ODF text document from Python, I hack Django templating to load an ODT file as a template. Long story short: Don’t try this at home. The fact that the application is still running in-production is very much a miracle.

Last week I suddenly stumble upon Appy pod. Oh if only I had found you sooner! Pod uses OpenOffice’s track changes feature to insert template placeholders and notes for conditionals and loops. This makes templates to be very simple to create. Aside from ODF, pod can also call OpenOffice in headless mode to generate the result PDF format.

Of course there are some limitations. You can’t put a word by word conditional, you need to use a paragraph. You can’t loop more than one row in a table. Also if there are errors, the error messages will be displayed as notes in the output document. While this simplifies debugging, it won’t look professional when it is seen by the user.

I you ever need to generate ODF documents from Python, do give pod a try!

  1. Word by word conditional is now possible by using a special function: test(someCondition, ‘InsertedIfTrue’, ‘InsertedIfFalse’). Each parameter can be any Python expression of method/function call.

    Once you are limited with standard pod features, you can switch to “raw ODT mode” by using the “do … from” statement. For example, if you want to render some tricky table where you have several kinds of rows, etc, you can write, in a pod statement (note) something like:

    do text
    from “… your custom stuff…”

    Is is better to call a function in Python code rather than write the ODT code into the pod template.

    If you want to know precise ODT syntax for writing simply
    create a table in a OpenOffice document, save it, rename it to zip,
    unzip it and consult content.xml.

  2. Hi Gaetan, thanks for the update. Thanks for pod as well. It’s a real gem. I’ll look into the new “test” function.

    What I really wish I could do quickly with pod is to do conditional styling. For instance I want a variable to be printed in bold if it satisfies a certain condition but normal if it doesn’t. It is possible using the pod statement combined with styling. But it gets a bit cumbersome when you have a 12 column table and each cell has needs to be conditionally styled.

Trackbacks & Pingbacks

  1. Helge Sander Helps Microsoft Again by Blocking ODF in Denmark | Boycott Novell

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: