1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
7 # Author : Nicolas Bessi (Camptocamp)
9 # WARNING: This program as such is intended to be used by professional
10 # programmers who take the whole responsability of assessing all potential
11 # consequences resulting from its eventual inadequacies and bugs
12 # End users who are looking for a ready-to-use solution with commercial
13 # garantees and support are strongly adviced to contract a Free Software
16 # This program is Free Software; you can redistribute it and/or
17 # modify it under the terms of the GNU General Public License
18 # as published by the Free Software Foundation; either version 2
19 # of the License, or (at your option) any later version.
21 # This program is distributed in the hope that it will be useful,
22 # but WITHOUT ANY WARRANTY; without even the implied warranty of
23 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 # GNU General Public License for more details.
26 # You should have received a copy of the GNU General Public License
27 # along with this program; if not, write to the Free Software
28 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 ##############################################################################
34 class WebKitHelper(object):
35 """Set of usefull report helper"""
36 def __init__(self, cursor, uid, report_id, context):
40 self.pool = pooler.get_pool(self.cursor.dbname)
41 self.report_id = report_id
43 def embed_image(self, type, img, width=0, height=0) :
44 "Transform a DB image into an embedded HTML image"
47 width = 'width="%spx"'%(width)
51 height = 'height="%spx"'%(height)
54 toreturn = '<img %s %s src="data:image/%s;base64,%s" />'%(
62 def get_logo_by_name(self, name):
63 """Return logo by name"""
64 header_obj = self.pool.get('ir.header_img')
65 header_img_id = header_obj.search(
70 if not header_img_id :
72 if isinstance(header_img_id, list):
73 header_img_id = header_img_id[0]
75 head = header_obj.browse(self.cursor, self.uid, header_img_id)
76 return (head.img, head.type)
78 def embed_logo_by_name(self, name, width=0, height=0) :
79 """Return HTML embedded logo by name"""
80 img, type = self.get_logo_by_name(name)
81 return self.embed_image(type, img, width, height)
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: