printing

22 views
Skip to first unread message

j...@sferacarta.com

unread,
Feb 3, 2013, 11:59:01 AM2/3/13
to sql...@googlegroups.com
Hi,
I found very interesting the way you use oo to create reports.
I can't figure out how to pass values (of type a) to the template.
Should it be passed as list of dictionaries or else.
I tried this:

from sqlkit.misc import oootemplate
from sqlkit.misc.oootemplate import Template , Context
from datetime import date
tmpl = Template('/tmp/my_template.odt')
context = Context({
'name' : 'Jo',
'last_name' : 'Soares',
'Table1' : [{'title':'Pinocchio',
'author':'Collodi',
'qty':3,
'price':1.32},
{'title':'La divina commedia',
'author':'Dante Alighieri',
'qty':3,
'price':32.2}
],
})

tmpl.render(context)
tmpl.save_as('/tmp/new_document.pdf')


the template is:
Spett/le Sig. $name $last_name,

Potete ordinare questi libri con il 20% di sconto

Titolo

Autore

Quantita'

prezzo

++$title

$author

$qty

$price


o questi con il 50% di sconto

Titolo

Autore

Quantita'

prezzo

++$title

$author

$qty

$price

Alessandro Dentella

unread,
Feb 5, 2013, 10:15:21 AM2/5/13
to sql...@googlegroups.com
On Sun, Feb 03, 2013 at 08:59:01AM -0800, j...@sferacarta.com wrote:
> Hi,
> I found very interesting the way you use oo to create reports.

pleased to know ;-)

> I can't figure out how to pass values (of type a) to the template.

what do you mean "of type a"?

> Should it be passed as list of dictionaries or else.

Context requires a dict, but table (the one that expands ++) requires a list
of items not a list of dictionaries, i.e.: list of instances of a class with
attributes named 'title', 'author',... The idea is that you normally will
render objects that live in a database and you retrieved using an ORM, that
maps each tuple to an instance.

I don't mind which class it belongs to as far as it has attributed named
according to the $names in your template ($title, $author, $qty...)

sandro
*:-)

--
Sandro Dentella *:-)
http://www.reteisi.org Soluzioni libere per le scuole
http://sqlkit.argolinux.org SQLkit home page - PyGTK/python/sqlalchemy



j...@sferacarta.com

unread,
Feb 6, 2013, 3:04:20 AM2/6/13
to sql...@googlegroups.com


Il giorno martedì 5 febbraio 2013 16:15:21 UTC+1, sandro dentella ha scritto:
On Sun, Feb 03, 2013 at 08:59:01AM -0800, j...@sferacarta.com wrote:
> Hi,
> I found very interesting the way you use oo to create reports.

pleased to know ;-)

> I can't figure out how to pass values (of type a) to the template.

what do you mean "of type a"?
sorry, I mean type b (Table with ++).
 

> Should it be passed as list of dictionaries or else.

Context requires a dict, but table (the one that expands ++) requires a list
of items not a list of dictionaries, i.e.: list of instances of a class with
attributes named 'title', 'author',...  The idea is that you normally will
render objects that live in a database and you retrieved using an ORM, that
maps each tuple to an instance.

I don't mind which class it belongs to as far as it has attributed named
according to the $names in your template ($title, $author, $qty...)

Very clever
of you
Sandro.
As I could not access the demo I could not understand how data were passed to Table1
so I took the liberty of making a few changes in oootemplate.py to be able to also pass a list of dictionaies to fill Table1.


diff /usr/lib/python2.5/site-packages/sqlkit/misc/oootemplate.py oootemplate1.py
285d284
<     oo_context = None
425,426d423
<             obj = self.content[table_name][list_num][record_index]
<             value = unicode(self.value2string(getattr(obj, key), key))
428c425,431
<             return unicode(match.sub(value))
---
>           obj = self.content[table_name][list_num][record_index]
>             if isinstance(obj, dict):
>               return obj[key]
>           else:
>               obj = self.content[table_name][list_num][record_index]
>               value = unicode(self.value2string(getattr(obj, key), key))
>               return unicode(match.sub(value))

I've been watching the project OOoPy and it seems to me that it do the same thing as PyUno with the difference that you do not need to install OpenOffice, so it should be more light and should also work with Solaris. What do you think of OOoPyi?


I did not understand how it is constructed  the menu demo (basic relation, mapper & fields, completion, layout, signals, hooks, uimanager, printing, sqledit)
are probably derived from the name of the scripts in the folder sql?
as in:

printing
       pdf
       preparing context
       related
       foreign key
       related foreign key

/usr/lib/python2.5/site-packages/demo/sql/ex_75_printing.py
/usr/lib/python2.5/site-packages/demo/sql/ex_76_printing_translate.py
/usr/lib/python2.5/site-packages/demo/sql/ex_77_printing-related.py
/usr/lib/python2.5/site-packages/demo/sql/ex_78_printing-fk.py
/usr/lib/python2.5/site-packages/demo/sql/ex_79_printing-related-fk.py
 

j...@sferacarta.com

unread,
Feb 7, 2013, 1:50:15 PM2/7/13
to sql...@googlegroups.com
Ok, You use the definition in the forst line of each script.
 

Alessandro Dentella

unread,
Feb 16, 2013, 5:46:55 AM2/16/13
to sql...@googlegroups.com
On Wed, Feb 06, 2013 at 12:04:20AM -0800, j...@sferacarta.com wrote:
> I've been watching the project OOoPy and it seems to me that it do the same
> thing as PyUno with the difference that you do not need to install OpenOffice,
> so it should be more light and should also work with Solaris. What do you think
> of OOoPyi?

I didn't know about it before you mentioned it. In my opinion il lacks
docuemntations and examples.

Another project that compares to that one is relatorio
(http://relatorio.openhex.org/) that could be worth a try.

sandro
*:-)

> I did not understand how it is constructed� the menu demo (basic relation,
> mapper &amp; fields, completion, layout, signals, hooks, uimanager, printing,
> sqledit)
> are probably derived from the name of the scripts in the folder sql?
> as in:

It's done reading the firt line of the examples.

j...@sferacarta.com

unread,
Feb 17, 2013, 1:58:14 AM2/17/13
to sql...@googlegroups.com


Il giorno sabato 16 febbraio 2013 11:46:55 UTC+1, sandro dentella ha scritto:
On Wed, Feb 06, 2013 at 12:04:20AM -0800, j...@sferacarta.com wrote:
> I've been watching the project OOoPy and it seems to me that it do the same
> thing as PyUno with the difference that you do not need to install OpenOffice,
> so it should be more light and should also work with Solaris. What do you think
> of OOoPyi?

I didn't know about it before you mentioned it. In my opinion il lacks
docuemntations and examples.

Another project that compares to that one is relatorio
(http://relatorio.openhex.org/) that could be worth a try.

Yes, it seems cool, I'm going to take a look at relatorio.
I wonder if it requires OpenOffice or not.
Thanks
 

sandro
*:-)

> I did not understand how it is constructed� the menu demo (basic relation,

Alessandro Dentella

unread,
Feb 17, 2013, 6:24:57 AM2/17/13
to sql...@googlegroups.com
On Sat, Feb 16, 2013 at 10:58:14PM -0800, j...@sferacarta.com wrote:
>
>
> Il giorno sabato 16 febbraio 2013 11:46:55 UTC+1, sandro dentella ha scritto:
> On Wed, Feb 06, 2013 at 12:04:20AM -0800, j...@sferacarta.com wrote:
> > I've been watching the project OOoPy and it seems to me that it do
> the same
> > thing as PyUno with the difference that you do not need to install
> OpenOffice,
> > so it should be more light and should also work with Solaris. What
> do you think
> > of OOoPyi?
>
> I didn't know about it before you mentioned it. In my opinion il
> lacks
> docuemntations and examples.
>
> Another project that compares to that one is relatorio
> (http://relatorio.openhex.org/) that could be worth a try.
>
> Yes, it seems cool, I'm going to take a look at relatorio.
> I wonder if it requires OpenOffice or not.

As far as I understand it uses Genshi template system and does not need
openoffice to produce .odt (and other oasis formats) but *i believe* it uses
tetex to produce pdf, i don't know how, but I saw a call to tetex.

THere's also a fork or relatorio alled aeroo library, that it's independant
from tex. I didn't understand if it depends on openerp thought...

http://www.alistek.com/index.php?option=com_content&id=93%3Aaeroo-reports-for-open-erp-5-a-6


sandro
*:-)

Reply all
Reply to author
Forward
0 new messages