relatorio Documentation

Similar documents
py3o.template Documentation

CSE 115. Introduction to Computer Science I

Scientific Python: matplotlib

For comprehensive certification training, students should complete Excel 2007: Basic, Intermediate, and Advanced. Course Introduction

Microsoft Office Excel 2010: Intermediate. Course Overview. Course Length: 1 Day. Course Overview

Part I - WORKING WITH ABSOLUTE REFERENCES

CenterStone. Reports User Guide. Manhattan Software Inc. World Leading Real Estate, Asset & Facilities Management Software.

Release notes SPSS Statistics 20.0 FP1 Abstract Number Description

InfoMaster REPORT DESIGNER

We do More VMAP DOCUMENTATION

Enhancing Your Customer Facing Documents (updated 10/03/2017)

Hands-On Lab. Lab: Developing BI Applications. Lab version: Last updated: 2/23/2011

OrgPublisher Photos, Logos, and Legends

Microsoft Office Excel 2010: Intermediate (R2) Course Overview. Course Outline

GO! with Microsoft Excel 2016 Comprehensive

Dolphin Dynamics. Enhancing Your Customer Facing Documents

Command Line and Python Introduction. Jennifer Helsby, Eric Potash Computation for Public Policy Lecture 2: January 7, 2016

SPSS Statistics 21.0 Fix Pack 1 Fix List

Simple sets of data can be expressed in a simple table, much like a

Sets. And ZIP codes?

Report Designer Report Types Table Report Multi-Column Report Label Report Parameterized Report Cross-Tab Report Drill-Down Report Chart with Static

IMAGE LINKS - INTRODUCTION

PrestaShop Product Properties Extension Multidimensional plugin

ComponentOne SharePoint Web Parts User Guide

Business Intelligence and Reporting Tools

python-docx-template Documentation

BusinessObjects Frequently Asked Questions

Macro calls are enclosed in two square brackets. Like Python functions, macros can also have arguments, a comma separated list within parentheses.

Calc Guide. Chapter 6 Printing, Exporting, and ing

What we already know. more of what we know. results, searching for "This" 6/21/2017. chapter 14

django-report-tools Documentation

Video Embedder. Plugin for Joomla! This manual documents version 9.x of the Joomla! extension.

TUTORIAL. HCS- Tools + Scripting Integrations

PBwiki Basics Website:

61A Lecture 2. Wednesday, September 4, 2013

Creating a new project To start a new project, select New from the File menu. The Select Insert dialog box will appear.

Christopher Lenz mediatis AG

Programming in Python Advanced

Telerik Training for Mercury 3

Hands-On Lab. Developing BI Applications. Lab version: Last updated: 2/23/2011

Appendix A Microsoft Office Specialist exam objectives

Creating a PowerPoint Presentation

Become strong in Excel (2.0) - 5 Tips To Rock A Spreadsheet!


Excel Templates. & Quote/Invoice Maker for ACT! v.5.0. for ACT! Another efficient and affordable ACT! Add-On by.

Tutorial for Loading and Updating ERP Template

Excel. Excel Options click the Microsoft Office Button. Go to Excel Options

Elixir Ad-hoc Report. Release Elixir Technology Pte Ltd

To add space around images, use the "padding" attribute. The code below will put 10 pixels of space around all four sides of an image:

EXCEL SKILLS. Selecting Cells: Step 1: Click and drag to select the cells you want.

Links Menu (Blogroll) Contents: Links Widget

Learning Microsoft Excel Module 1 Contents. Chapter 1: Introduction to Microsoft Excel

Table of Contents. Windows Interface Elements (Home Page) Contents. Select Chart... Elements

Manual Getting Started. How to install extension

yawrap Documentation Release Michal Kaczmarczyk

Microsoft Office Excel 2010: Basic. Course Overview. Course Length: 1 Day. Course Overview

Scope Monthly. Guide to updating and maintaining the Scope Monthly Website. Last Updated: Table of Contents

django-cms-search Documentation

PVB CONTACT FORM 7 CALCULATOR PRO DOCUMENTATION

V-BOX Cloud Configuration

Telerik Training for Mercury 3

NetAdvantage for ASP.NET Release Notes

Create Custom Dashboards

Rediscover Charts IN THIS CHAPTER NOTE. Inserting Excel Charts into PowerPoint. Getting Inside a Chart. Understanding Chart Layouts

Strategic Series-7001 Introduction to Custom Screens Version 9.0

UNIT 4. Research Methods in Business

OrgChart Now WordPress Org Chart Links. OfficeWork Software LLC

Highlight the s address (example: and go to the top of the page and click on Insert

COMPUTER APPLICATIONS TECHNOLOGY

Microsoft Excel Pivot Tables & Pivot Table Charts

Elixir Ad-hoc Report. Release Elixir Technology Pte Ltd

ARTIFICIAL INTELLIGENCE AND PYTHON

Unit E Step-by-Step: Programming with Python

Audience: - Executives and managers who have already been using MS Office want to migrate to Libre Office suit.

1 Woocommerce Products Designer

Maximizer CRM. Customer Service Maximizer CRM 2017 VERSION COMPARISON FOR WEB ACCESS (EMEA) Maximizer CRM 2016/R2.

Learning Microsoft Excel Module 1 Contents. Chapter 1: Introduction to Microsoft Excel

Data Science with Python Course Catalog

The figure below shows the Dreamweaver Interface.

Simple Form Documentation

CMS (Content Management System) for Beginners A Step by Step Approach

Getting Started with CSS Sculptor 3

USER MANUAL. Contents. Analytic Reporting Tool Basic for SUITECRM

Statistics and Graphics Functions

PRACTICE EXERCISES. Family Utility Expenses

Designing Ad hoc Reports. Version: 16.0

Data Science and Machine Learning Essentials

CounselLink Reporting. Designer

Sample Document. Easy Way. Teach yourself... A Cheryl Price Publication. Microsoft Excel 2010 (Level 3)

The Mathcad Workspace 7

STEPHEN WOLFRAM MATHEMATICADO. Fourth Edition WOLFRAM MEDIA CAMBRIDGE UNIVERSITY PRESS

pyprika Documentation

THE INDIAN COMMUNITY SCHOOL, KUWAIT

Intellicus Enterprise Reporting and BI Platform

Charts and graphs WordPress Visual Designer

Editing ReqIF-XHTML fragments with Writer

Working with Smart View. Version: 16.0

Manual For The ISPConfig 3 Billing Module

Chart And Graph. Features. Features. Quick Start Folders of interest Bar Chart Pie Chart Graph Chart Legend

CS Lab 8. Part 1 - Basics of File I/O

Transcription:

relatorio Documentation Release 0.8.1 Nicolas Évrard, CGaëtan de Menten, Cédric Krier Jun 25, 2018

Contents 1 Quick Example 3 1.1 Data.................................................... 3 1.2 Template................................................. 4 1.3 Generate the final documents...................................... 5 2 Indepth Example 7 2.1 Create a simple OpenOffice Writer template.............................. 8 2.2 One step further: OpenOffice Calc and OpenOffice Impress templates................. 10 2.3 Everybody loves charts.......................................... 12 2.4 A (not-so) real example......................................... 13 i

ii

Contents: Contents 1

2 Contents

CHAPTER 1 Quick Example In this page we will show you how you can create OpenOffice documents using Relatorio. 1.1 Data We need some data objects to work on, so let s first create a fake invoice object. Please create a file named data.py in your favorite text editor, and copy the following content: from os.path import join, dirname class Invoice(dict): @property def total(self): return sum(l['amount'] for l in self['lines']) @property def vat(self): return self.total * 0.21 inv = Invoice(customer={'name': 'John Bonham', 'address': {'street': 'Smirnov street', 'zip': 1000, 'city': 'Montreux'}}, lines=[{'item': {'name': 'Vodka 70cl', 'reference': 'VDKA-001', 'price': 10.34}, 'quantity': 7, 'amount': 7 * 10.34}, {'item': {'name': 'Cognac 70cl', 'reference': 'CGNC-067', (continues on next page) 3

'price': 13.46}, 'quantity': 12, 'amount': 12 * 13.46}, {'item': {'name': 'Sparkling water 25cl', 'reference': 'WATR-007', 'price': 4}, 'quantity': 1, 'amount': 4}, {'item': {'name': 'Good customer', 'reference': 'BONM-001', 'price': -20}, 'quantity': 1, 'amount': -20}, ], id='mzy-20080703', status='late', bottle=(open(join(dirname( file ), 'bouteille.png'), 'rb'), 'image/png')) So we created the data for an invoice for the famous Led Zeppelin s drummer and his favorite addiction. (continued from previous page) 1.2 Template The next thing to do is to create a template for invoices. We will use the one displayed below. To create the Genshi directives, you need to create a text-type placeholder field, and fill it with the expression you want to use. 4 Chapter 1. Quick Example

1.3 Generate the final documents Now that we have both a template and some data, we can now start to use Relatorio to create John Bonham s particular invoice. So fire up your favorite python interpreter (we suggest using IPython) and type (or copy-paste) the following commands: from relatorio.templates.opendocument import Template from data import bonham_invoice basic = Template(source='', filepath='basic.odt') basic_generated = basic.generate(o=bonham_invoice).render() file('bonham_basic.odt', 'wb').write(basic_generated.getvalue()) On the first line we import the opendocument Template engine. This class has the same signature as the one from Genshi but uses only the filepath argument. On the fourth line, we generate the final document from the template and the data. Note how we pass o=bonham_invoice as argument to generate. This is the same o variable as was used in the O dt template we just created. render() returns us a StringIO object, which is then used to pipe the result to a file. 1.3. Generate the final documents 5

And so here is our invoice with all the fields completed according to the Invoice object we created earlier. Notice how the style we set in the template are also applied in the resulting invoice. In this example, we only used the py:for directive, but Relatorio also supports other Genshi directives: py:if, py:choose / py:when / py:otherwise and py:with. 6 Chapter 1. Quick Example

CHAPTER 2 Indepth Example In this page I will detail the way I created the reports that can be found in the examples directory. Let s start with the content of common.py, this file stores the definition of an invoice that will be used to create the different reports. The invoice is a simple python dictionary with some methods added for the sake of simplicity: from os.path import join, dirname class Invoice(dict): @property def total(self): return sum(l['amount'] for l in self['lines']) @property def vat(self): return self.total * 0.21 inv = Invoice(customer={'name': 'John Bonham', 'address': {'street': 'Smirnov street', 'zip': 1000, 'city': 'Montreux'}}, lines=[{'item': {'name': 'Vodka 70cl', 'reference': 'VDKA-001', 'price': 10.34}, 'quantity': 7, 'amount': 7 * 10.34}, {'item': {'name': 'Cognac 70cl', 'reference': 'CGNC-067', 'price': 13.46}, 'quantity': 12, 'amount': 12 * 13.46}, {'item': {'name': 'Sparkling water 25cl', 'reference': 'WATR-007', (continues on next page) 7

'price': 4}, 'quantity': 1, 'amount': 4}, {'item': {'name': 'Good customer', 'reference': 'BONM-001', 'price': -20}, 'quantity': 1, 'amount': -20}, ], id='mzy-20080703', status='late', bottle=(open(join(dirname( file ), 'bouteille.png'), 'rb'), 'image/png')) (continued from previous page) 2.1 Create a simple OpenOffice Writer template Let s start with the simple template defined in basic.odt. This report will be created and rendered with the following three line of code: from relatorio.templates.opendocument import Template basic = Template(source='', filepath='basic.odt') (continues on next page) 8 Chapter 2. Indepth Example

(continued from previous page) file('bonham_basic.odt', 'wb').write(basic.generate(o=inv).render().getvalue()) Notice that the dictionary passed to generate is used to bind names to make them accessible to the report. So you can access the data of the invoice with a Text Placeholder containing o.customer.name. This is where you can see our Genshi heritage. In fact, all reports using relatorio are subclasses of Genshi s Template. Thus you can use most of the goodies provided by Genshi. To iterate over a list you must use an hyperlink (created through Insert > Hyperlink ) and encode as the target the Genshi expression to use. The URL-scheme used must be relatorio. You can use whatever text you want as the link text, but we find it way more explicit to display the Genshi code used. Here is the example of the for loop. And thus here is our invoice, generated through relatorio: 2.1. Create a simple OpenOffice Writer template 9

2.2 One step further: OpenOffice Calc and OpenOffice Impress templates Just like we defined a Writer template it is just as easy to define a Calc/Impress template. Let s take a look at pivot. ods. 10 Chapter 2. Indepth Example

As usual you can see here the different way to make a reference to the content of the invoice object: through the Text Placeholder interpolation of Genshi or through the hyperlink specification I explained earlier. Note that there is another tab in this Calc file used to make some data aggregation thanks to the data pilot possibilities of OpenOffice. And so here is our rendered template: 2.2. One step further: OpenOffice Calc and OpenOffice Impress templates 11

Note that the type of data is correctly set even though we did not have anything to do. 2.3 Everybody loves charts Now we would like to make our basic report a bit more colorful, so let s add a little chart. We are using PyCha to generate them from our pie_chart template: options: width: 600 height: 400 background: {hide: true} legend: {hide: true} axis: {labelfontsize: 14} padding: {bottom: 10, left: 10, right: 10, top: 10} chart: type: pie output_type: png dataset: {% for line in o.lines %} - - ${line.item.name} - - [0, $line.amount] {% end %} Once again we are using the same syntax as Genshi but this time this is a TextTemplate. This file follow the YAML format thus we can render it into a data structure that will be sent to PyCha: 12 Chapter 2. Indepth Example

the options dictionary will be sent to PyCha as-is the dataset in the chart dictionary is sent to PyCha through its.adddataset method. If you need more information about those go to the pycha website. And here is the result: 2.4 A (not-so) real example Now that we have everything to start working on our complicated template invoice.odt, we will go through it one step at a time. 2.4. A (not-so) real example 13

In this example, you can see that not only the openoffice plugin supports the for directive, it also supports the if directive and the choose directive that way you can choose to render or not some elements. The next step is to add images programmatically, all you need to do is to create frame ( Insert > Frame ) and name it image: expression just like in the following example: 14 Chapter 2. Indepth Example

The expression when evaluated must return a couple whose first element is a file object containing the image and second element is its mimetype. Note that if the first element of the couple is an instance of relatorio report then this report is rendered (using the same arguments as the originating template) and used as a the source for the file definition. This kind of setup gives us a nice report like that: 2.4. A (not-so) real example 15

16 Chapter 2. Indepth Example