Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
3 Odpowiedzi
21193 Widoki

Hi everybody,

I would like to add an image to a xml file.

This image is stored on the database (like res_partner.image).

How is possible to print this image on a xml file?

It will be nice to have this image with a sql request (cr.execute) and convert it in binary or in picture in order to have the possibility to print it.

Thank you a lot

Selverine

Awatar
Odrzuć

<img t-att-src="widget.get_image_url(category)" />

Najlepsza odpowiedź

You can load your image in any form that have image field (for example Product). And then export this field to CSV file. Open CSV file in Excel and copy data of image in ANSII text format. After it paste data to your XML file.

Awatar
Odrzuć

You can use features "encodestring" and "decodestring" of base64 module in python to do this.

Najlepsza odpowiedź

It is, and you can find examples in the standard modules. The trick is to convert the image to base64. Yiou can find a tool, do it with a small Python script, or even use a website service for that (there are several on the web).

For an example have a look at addons/base/res/res_partner_demo.xml.

Awatar
Odrzuć
Autor

Dear Daniel Reis, thank your for your help. I don't find other function. I try this cr.execute('SELECT res_company.logo_web FROM res_company') res = cr.fetchall() v['logoTmp'] = base64.decodestring(str(res[0])), and others fonctions without results. Have you some idea please? Thanks a lot!

Autor Najlepsza odpowiedź

Hi wowas, OpenERP Vietnam,

Thank you, really, for your help. I will be more precise about my problem: I use the code below:

cr.execute('SELECT res_company.logo_web FROM res_company') res = cr.fetchall() v['logo_Print'] = res[0]

I would to put in the field logo_Print, the picture that is stored in the table: res_company, field logo_web, id = one. I think that maybe there is an fonction to translate bytea image (field in database) into binary in my python code, no?

Thnak you!

Selverine

[Edit] Now, i try with :

cr.execute('SELECT res_company.logo_web FROM res_company') res = cr.fetchall() v['logoTmp'] = base64.decodestring(str(res[0]))

But still doesn't work, any idea please? How is possible to convert an "tuple" into a string? Or maybe, need i to get the picture differently?

Thank!!

Awatar
Odrzuć

Hi Selverine, python will translate from bytea (in database) into <type 'buffer'> in your python code.

Powiązane posty Odpowiedzi Widoki Czynność
2
gru 23
11877
3
lip 22
22062
2
cze 21
17811
0
wrz 20
3163
0
maj 16
3544