Entries in the Category “relatorio”

How to make mutually beneficient unfriendly forks ?

written by nicoe, on Jan 18, 2011 5:53:00 PM.

Last week I learned about aeroolib a not so friendly fork of relatorio. It left me wondering about how to handle such a situation. Granted relatorio suffered from a lack of attention since I started to work for PCSol, but since I left, I intend to push for a greater integration of it into tryton.

I was disappointed because I never heard of this company using relatorio and all of a sudden they announce that they forked our project and added some nice features. The guy behind this company had posted 2 bugs (one of them after having talk with him in great length on IRC) and never posted any message on our mailing list. One thing amongst other that really got on my nerves was that the new project fixed a (so called) security breach, and they did not warn us about that issue ! And eventhough they did grant us the copyright on our work (they had too, that's why I choose the GPL when writing this piece of software after all) I felt that the collaboration should have been better.

But next time you intend to fork project do it right:

  • keep the development history (for such little projects using tailor is a piece of cake), it might prove usefull and you have the opportunity to clearly separate what are your developments and what were the original ones. For now all we have is a big fat commit and it has made our work of patching relatorio more difficult (on a side note : do not comment stuff in your repository, bazaar won't forget those lines you are deleting you know).
  • do not, I repeat, do not removed all the test cases : I bet that sooner or later you will have to write them again.
  • talk to the maintainers on the mailing list or on IRC about your issues. We now have to libraries, amongst many others, that do opendocument rendering based on genshi templates.

Those little advices will ease our work and yours. A fork, even an unfriendly one, might be mutually beneficient.

Our trac is more welcoming now

written by nicoe, on Apr 17, 2009 3:49:00 PM.

Since we released a new version of relatorio (our openoffice templating tool if you never heard of it) yesterday, I took this opportunity to install trac's account manager plugin. It was surprisingly easy (I had memories installing the mercurial plugin where I had to debug the code and so on) and works like a charm !

So from now on you can register yourself on our trac and use your own login/password to login, which means you can get notifications when there are changes on content you are monitoring.

PS: On a side note, I started toying with the whole microblogging stuff, you'll find me on identi.ca.

relatorio is available to debian users

written by nicoe, on Mar 9, 2009 9:14:00 AM.

I am quite happy to inform you that relatorio is now packaged in the debian distribution !

We should make a release quite soon, since there is a bug fixing a huge regression on py:when tags.

relatorio 0.5 is released

written by nicoe, on Jan 23, 2009 1:23:00 PM.

I'm quite happy to announce the new release of relatorio. Thanks to the sponsoring of b2ck, we added some nice features such as looping on columns in OOTemplates and the improvements in the closing/opening tag detection algorithm, many thanks to them !

Here is the full changelog:

  • Added Text and XML Template to the TemplateLoader
  • Splitted mimetypes and ids in the ReportRepository
  • RelatorioStream now has a __str__ method
  • OOTemplate: ChartTemplate can be included
  • OOTemplate: Correctly handle content type in the table cells
  • OOTemplate: Better closing/opening tag detection algorithm
  • OOTemplate: Looping on columns now work in OOTemplates
  • OOTemplate: Using compression

And here is a screenshot of the looping feature:

Loops on columns work now !

Well the colours are not great but I'm not the one to blame !

Some relatorio documentation love

written by nicoe, on Nov 23, 2008 4:45:00 PM.

With the recent release of tryton, I felt the need to give the relatorio website some love. Thus I added some documentation and Ged created a logo and a favicon.

relatorio logo

At least now, people will not need to dig into the examples directory to know how to generate odf files from their python objects.

Do not hesitate to report bugs and misfeatures in the documentation.

Charts in relatorio

written by nicoe, on Aug 26, 2008 4:37:00 PM.

Since this is my first post on planet python: Hello !!

A few days ago, I commited a change that enables relatorio to output charts in png. I use PyCha as the plotting module since its graphics looked appealing and the syntax was simple enough to be used by lambda users. Since PyCha does not support negative values, I patched it and while I was working on it I also add a few features that I hope to see included upstream.

a chart made with PyCha

The nice stuff about this is that I can finally include a chart into an ODF file without to much hurdle, it works just like an image, the OpenDocument plugin will detect you are using a relatorio report and make the necessary call to create the chart.

a chart in an ODT file

This is all good and fine except that I don't like the way I templatize (is that a word) the chart: I use a genshi template of a yaml file like this one:

options:
    background: {hide: true}
    legend: {hide: true}
    padding: {bottom: 10, left: 70, right: 10, top: 10}
chart:
    type: pie
    width: 600
    height: 400
    dataset:
    {% for line in o.lines %}
      - - ${line.item.name}
        - - [0, $line.amount]
    {% end %}

When this file is generated with the relevant data, the options dictionary is transmitted to PyCha and the chart dictionary is then used to create the chart. Going through the yaml step feels like it is unnecessary but I fail to see how I can make this work without requesting the user to learn python.

relatorio: lots of new features

written by nicoe, on Aug 8, 2008 7:53:00 AM.

Lately, I added some new features to relatorio.

  • The use of ConTeXt to generate pdf files, it thus remove the dependancy on the trml2pdf that has not seen a release in age. It also shows how you can use a shell command to generate documents.
  • Support for the opendocument spreadsheet and presentation files, the help of Udo Spallek has been precious for this. So with relatorio, you can now generate a dump of your data, and use it to construct pivot table (we geeks do not know what it is but believe me it is a key knowledge for every big business consultant), and presentations.

The openoffice change involve a change in the way you add your variables to the template. In previous versions we were using tags, but it was not possible to add them through OO UI (and that they get replaced if you add them by hand) in Calc. We choose to replace it by tags, the URL must start with relatorio:// and be followed by your directive or expression. As some people have noted, this could create hard to find bugs if the href differs from the content of the tag (ie what is displayed), thus I included a warning in that case. But I think that if you are using the genshi interpolation feature there should be only structural information in the A tags.

Another nice addition to the openoffice templating mechanism, is that now we support inner documents. Thus if you include an opendocument spreadsheet in a text document, the data inside the spreadsheet will be interpreted as well.


UPDATE: finally, relatorio now supports both the old syntax and the new one.

More relatorio love

written by nicoe, on Aug 1, 2008 9:13:00 AM.

Lately I got a lot of help from Cédric of b2ck (another bunch of ex-tiny employees) so that they can replace the openerp way to do things (they are using the deprecated .sxw format) by relatorio openoffice reports.

In order to meet their needs, I complety reviewed the way the openoffice template is written. We work now much more similarly to other genshi templates and it brings some nice goodies :

  • generate outputs a genshi Stream that can be rendered as an OpenOffice document,
  • testing is way more easy,
  • you can apply filters to this stream in order to translate the document,
  • styles.xml is now templateable, that way you can make use of openoffice template documents

Cédric also pointed me to bugs in my setup.py and in the way I handled the namespaces from the OO documents. Opening relatorio development really brought us a lot of good ideas and feedback. I am really glad we did this and we will keep doing it at a faster pace then previously planned.

Switched relatorio to mercurial

written by nicoe, on Jul 29, 2008 1:52:00 PM.

I took some time today and yesterday to switch the relatorio repository to mercurial. The hardest thing in the migration was the Trac plugin that had a SyntaxError and some mess with easy_install.

Next on my schedule: migrating our framework and our client to mercurial. I expect this to be somewhat more difficult since they share the same subversion repository and I'd like to split them in two different hg repository.

Announcing relatorio !

written by nicoe, on Jul 7, 2008 10:28:00 AM.

Today, I'm very proud to announce the birth of our new project : relatorio, a reporting module able to generate a whole lot of different document types from templates. relatorio is a Portuguese word that means report, I choose Portuguese because the Spanish/French words did not sound good enough.

Technically, we are using genshi and trml2pdf (the homepage does not work anymore) to create PDF and OpenOffice documents.

In this post I'll show you how easy it is to create OpenOffice documents using relatorio. First we need some objects to work on. Let's create a fake invoice object:

class Invoice(dict):
    @property
    def total(self):
        return reduce(operator.add, (l['amount'] for l in self['lines']), 0)
    @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',
                               'price': 0.4},
                      'quantity': 1,
                      'amount': 0.4},
                     {'item': {'name': 'Good customer rebate',
                               'reference': 'BONM-001',
                               'price': -20},
                      'quantity': 1,
                      'amount': -20},
                    ],
              id='MZY-20080703',
              status='late')

So we created an invoice for the famous Led Zeppelin's drummer and his favorite addiction.

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 just need to create a text-type placeholder [1] field, and fill it with the expression you want to use.

A simple invoice OpenOffice document template

You can now start to use relatorio to create John Bonham's invoice.

from relatorio.templates.odt import Template
basic = Template(source=None, filepath='basic.odt')
file('bonham_basic.odt', 'w').write(basic.generate(o=inv).getvalue())

On the first line we import the odt Template engine. This class has the same signature as the one from genshi but uses only the filepath arguments. It returns a StringIO object that can be used to write the report on the disc.

The simple template filled with Bonham's invoice

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.

We made use of the py:for directive. But it is not the only genshi directive supported by the relatorio odt plugin, it also support py:if, py:choose/py:when/py:otherwise and py:with.

An example demonstrating all the genshi directives used by relatorio

We also included a simple report repository that allows you to link your reports to a class and retrieve them by the name you gave them or by the mimetype they output.

>>> import relatorio
>>> repos = relatorio.ReportRepository()
>>> repos.add_report(Invoice, 'application/vnd.oasis.opendocument.text',
...                  'basic.odt', report_name='basic')
>>> repos.add_report(Invoice, 'application/vnd.oasis.opendocument.text',
...                  'invoice.odt', report_name='complicated')
>>> repos.reports[Invoice]['basic']
('application/vnd.oasis.opendocument.text',
 )
>>> repos.reports[Invoice]['application/vnd.oasis.opendocument.text']
[('basic',
  ),
 ('complicated',
  )]

Moreover, the report repository works with a TemplateLoader object that automatically reloads a template when the file used to create it has been modified.

When using the report repository, you're also working with the relatorio reports, those are proxies over a Template that enables you to pre-process data before rendering it. The default behavior is to bind your object to the template variable o and all other arguments to the variable args. Here is an example showing you how you could use it in cherrypy to make the request object available to all your reports.

class OHFactory(relatorio.DefaultFactory):
   def __call__(self, obj, **kwargs):
       data = {}
       data['o'] = obj
       data['args'] = kwargs
       data['request'] = cherrypy.request
       return data

I hope you will find this module usefull and abuse it in every way.

[1]Created using Ctrl-F2 with the standard mapping of OpenOffice.