Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

Take the power of Jinja2 templates to OpenOffice and LibreOffice and create reports and letters in your web applications

Project Description

# SECRETARY

#### Take the power of Jinja2 templates to OpenOffice and LibreOffice and create reports in your web applications.

Secretary allows you to use Open Document Text (ODT) files as templates for rendering reports or letters. Secretary is an alternative solution for creating office documents and reports in OpenDocument Text format from templates that can be visually composed using the OpenOffice.org/LibreOffice Writer word processor.

Secretary use [the semantics of jinja2 templates][1] to render ODT files. Most features in jinja can be used into your ODT templates including variable printing, filters and flow control.

Rendered documents are produced in ODT format, and can then be converted to PDF, MS Word or other supported formats using the UNO Bridge or a library like [PyODConverter][2]

## Installing

pip install secretary

## Rendering a Template

from secreatary import Render

engine = Render(template) result = engine.render(foo=foo, bar=bar)

Secretary implements a class called Render. Render takes a single argument called template which is a template file. template can be a filename or a file object.

To render a template create an instance of class Render and call the instance’s method render passing the template variables as keyword arguments. render will return the rendered document in binary format.

Before rendering a template, you can configure the internal templating engine using the Render instance’s variable environment, which is an instance of jinja2 [Environment][3] class. For example, to declare a custom filter use:

from secreatary import Render

engine = Render(template)

# Configure custom application filters engine.environment.filters[‘custom_filer’] = filter_function result = engine.render(foo=foo, bar=bar)

output = open(‘rendered_document.odt’, ‘w’) output.write(result)

## Composing Templates

Secretary templates are simple ODT documents. You can create them using Writer. An OpenDocument file is basically a ZIP archive containing some XML files. If you plan to use control flow or conditionals it is a good idea to familiarise yourself a little bit with the OpenDocument XML to understand better what’s going on behind the scenes.

### Printing Variables

Since Secretary use the same template syntax of Jinja2, to print a varible type a double curly braces enclosing the variable, like so:

{{ foo.bar }} {{ foo[‘bar’] }}

However, mixing template instructions and normal text into the template document may become confusing and clutter the layout. Secretary recommends using an alternative way of inserting fields. Insert a visual field in LibreOffice Writer from the menu Insert > Fields > Other… (or just press Ctrl+F2), then click on the Functions tab and select Input field. Click Insert. A dialog will appear where you can insert the print instructions. You can even insert simple control flow tags to dynamically change what is printed in the field.

Secretary will handle multiline variable values replacing the line breaks with a <text:line-break/> tag.

### Control Flow

To be documented…

### Builtin Filters Apart of the available Jinja2 filters. Secretary includes some additionals filters. These are:

Release history Release notifications

History Node

0.2.19

History Node

0.2.18

History Node

0.2.17

History Node

0.2.16

History Node

0.2.15

History Node

0.2.14

History Node

0.2.13

History Node

0.2.12

History Node

0.2.11

History Node

0.2.10

History Node

0.2.9

History Node

0.2.8

History Node

0.2.7

History Node

0.2.6

History Node

0.2.5

History Node

0.2.4

History Node

0.2.3

History Node

0.2.2

History Node

0.2.1

History Node

0.2.0

This version
History Node

0.1.0

History Node

0.0.2

History Node

0.0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
secretary-0.1.0.linux-i686.exe (75.0 kB) Copy SHA256 hash SHA256 Windows Installer any Feb 3, 2014
secretary-0.1.0.tar.gz (26.9 kB) Copy SHA256 hash SHA256 Source None Feb 3, 2014

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page