[FIX] wall widget: fixed variable not refreshed
[odoo/odoo.git] / addons / report_webkit / report_helper.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com) 
5 # All Right Reserved
6 #
7 # Author : Nicolas Bessi (Camptocamp)
8 #
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
14 # Service Company
15 #
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.
20 #
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.
25 #
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.
29 #
30 ##############################################################################
31
32 import pooler
33
34 class WebKitHelper(object):
35     """Set of usefull report helper"""
36     def __init__(self, cursor, uid, report_id, context):
37         "constructor"
38         self.cursor = cursor
39         self.uid = uid
40         self.pool = pooler.get_pool(self.cursor.dbname)
41         self.report_id = report_id
42         
43     def embed_image(self, type, img, width=0, height=0) :
44         "Transform a DB image into an embedded HTML image"
45
46         if width :
47             width = 'width="%spx"'%(width)
48         else :
49             width = ' '
50         if height :
51             height = 'height="%spx"'%(height)
52         else :
53             height = ' '
54         toreturn = '<img %s %s src="data:image/%s;base64,%s" />'%(
55             width,
56             height,
57             type, 
58             str(img))
59         return toreturn
60             
61             
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(
66                                             self.cursor, 
67                                             self.uid, 
68                                             [('name','=',name)]
69                                         )
70         if not header_img_id :
71             return u''
72         if isinstance(header_img_id, list):
73             header_img_id = header_img_id[0]
74
75         head = header_obj.browse(self.cursor, self.uid, header_img_id)
76         return (head.img, head.type)
77             
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)
82         
83
84 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: