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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
30 ##############################################################################
34 class WebKitHelper(object):
35 """Set of usefull report helper"""
36 def __init__(self, cursor, uid, report_id, context):
40 self.pool = openerp.registry(self.cursor.dbname)
41 self.report_id = report_id
42 self.context = context
44 def embed_image(self, type, img, width=0, height=0) :
45 "Transform a DB image into an embedded HTML image"
48 width = 'width="%spx"'%(width)
52 height = 'height="%spx"'%(height)
55 toreturn = '<img %s %s src="data:image/%s;base64,%s" />'%(
63 def get_logo_by_name(self, name):
64 """Return logo by name"""
65 header_obj = self.pool.get('ir.header_img')
66 header_img_id = header_obj.search(
71 if not header_img_id :
73 if isinstance(header_img_id, list):
74 header_img_id = header_img_id[0]
76 head = header_obj.browse(self.cursor, self.uid, header_img_id)
77 return (head.img, head.type)
79 def embed_logo_by_name(self, name, width=0, height=0):
80 """Return HTML embedded logo by name"""
81 img, type = self.get_logo_by_name(name)
82 return self.embed_image(type, img, width, height)
84 def embed_company_logo(self, width=0, height=0):
85 cr, uid, context = self.cursor, self.uid, self.context
86 my_user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
87 logo = my_user.company_id.logo_web
88 return self.embed_image("png", logo, width, height)
92 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: