Merge lp:~camptocamp/ocb-addons/7.0-webkit_report-image_helper-20130318 into lp:ocb-addons

Proposed by Yannick Vaucher @ Camptocamp
Status: Superseded
Proposed branch: lp:~camptocamp/ocb-addons/7.0-webkit_report-image_helper-20130318
Merge into: lp:ocb-addons
Diff against target: 73 lines (+16/-15)
1 file modified
report_webkit/report_helper.py (+16/-15)
To merge this branch: bzr merge lp:~camptocamp/ocb-addons/7.0-webkit_report-image_helper-20130318
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp philosophical musing Needs Information
Stefan Rijnhart (Opener) Needs Fixing
Review via email: mp+153775@code.launchpad.net

This proposal has been superseded by a proposal from 2013-03-18.

Description of the change

In image helper, fix construction of image tag and improve it to let use other units than px (better to use mm and cm for reports)

This MP is a forward port of the following:
https://code.launchpad.net/~camptocamp/openobject-addons/6.0-webkit_report-image_helper-20120719
https://code.launchpad.net/~camptocamp/openobject-addons/6.1-webkit_report-image_helper-20120719

To post a comment you must log in.
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

lines 10,29,34,35,42,43,53,60 contain meaningless whitespace changes. Can you please restore these lines from the original version of the file, to prevent unnecessary risk of conflicts?

review: Needs Fixing
Revision history for this message
Stefan Rijnhart (Opener) (stefan-opener) wrote :

And could you create a bug report, so that we can easily track upstream attempts at fixing this?

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Bug report created and linked

Revision history for this message
Alexandre Fayolle - camptocamp (alexandre-fayolle-c2c) wrote :

I have mixed feelings about this one, as it is not a "bug" but an enhancement. Allowing it will mean that some addons will not work at all with the official branch and work with this one (because they use a unit). IMO, it creates an unnecessary incompatibility.

Opinion?

review: Needs Information (philosophical musing)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

It shouldn't create incompatibility as the added argument "unit" is optional and if unset, it will be "px" still.

In my opinion, this will only make it available and we can make other webkit exemple header keeping the pixel sizes.

In fact, it will be useful for real custom reports, we do not care to have it yet example reports.
When you use webkit and set your logo you will have to create your own specific header and at that time you should be able to use a metric unit.

If you receive some corporation identities rules it will be in mm or cm and as you have only pixels, you will be cursing developers for each tries of conversion convert from cm to pixels.

So for the sake of developers who don't want to be haunted during there dreams, this should be accepted.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'report_webkit/report_helper.py'
2--- report_webkit/report_helper.py 2012-12-06 14:56:32 +0000
3+++ report_webkit/report_helper.py 2013-03-18 14:23:25 +0000
4@@ -4,7 +4,7 @@
5 # Copyright (c) 2010 Camptocamp SA (http://www.camptocamp.com)
6 # All Right Reserved
7 #
8-# Author : Nicolas Bessi (Camptocamp)
9+# Authors : Nicolas Bessi (Camptocamp)
10 #
11 # WARNING: This program as such is intended to be used by professional
12 # programmers who take the whole responsability of assessing all potential
13@@ -39,19 +39,19 @@
14 self.uid = uid
15 self.pool = pooler.get_pool(self.cursor.dbname)
16 self.report_id = report_id
17-
18- def embed_image(self, type, img, width=0, height=0) :
19+
20+ def embed_image(self, type, img, width=0, height=0, unit="px"):
21 "Transform a DB image into an embedded HTML image"
22
23 if width :
24- width = 'width="%spx"'%(width)
25+ width = 'width: %s%s;'%(width, unit)
26 else :
27 width = ' '
28 if height :
29- height = 'height="%spx"'%(height)
30+ height = 'height: %s%s;'%(height, unit)
31 else :
32 height = ' '
33- toreturn = '<img %s %s src="data:image/%s;base64,%s" />'%(
34+ toreturn = '<img style="%s%s" src="data:image/%s;base64,%s" />'%(
35 width,
36 height,
37 type,
38@@ -59,14 +59,15 @@
39 return toreturn
40
41
42- def get_logo_by_name(self, name):
43+ def get_logo_by_name(self, name, company_id=None):
44 """Return logo by name"""
45 header_obj = self.pool.get('ir.header_img')
46- header_img_id = header_obj.search(
47- self.cursor,
48- self.uid,
49- [('name','=',name)]
50- )
51+ domain = [('name','=',name)]
52+ if company_id:
53+ domain.append(('company_id', '=', company_id))
54+ header_img_id = header_obj.search(self.cursor,
55+ self.uid,
56+ domain)
57 if not header_img_id :
58 return u''
59 if isinstance(header_img_id, list):
60@@ -75,10 +76,10 @@
61 head = header_obj.browse(self.cursor, self.uid, header_img_id)
62 return (head.img, head.type)
63
64- def embed_logo_by_name(self, name, width=0, height=0):
65+ def embed_logo_by_name(self, name, width=0, height=0, unit="px", company_id=None):
66 """Return HTML embedded logo by name"""
67- img, type = self.get_logo_by_name(name)
68- return self.embed_image(type, img, width, height)
69+ img, type = self.get_logo_by_name(name, company_id=company_id)
70+ return self.embed_image(type, img, width, height, unit)
71
72
73 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: