openerp-community-reviewer team mailing list archive
-
openerp-community-reviewer team
-
Mailing list archive
-
Message #06720
[Merge] lp:~camptocamp/ocb-addons/7.0-fix-1319109 into lp:ocb-addons
Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/ocb-addons/7.0-fix-1319109 into lp:ocb-addons.
Requested reviews:
OpenERP Community Backports (ocb)
Related bugs:
Bug #1319109 in OpenERP Community Backports (Addons): "webkit_report - webkit parser is not thread safe because of attribute parser_instance"
https://bugs.launchpad.net/ocb-addons/+bug/1319109
For more details, see:
https://code.launchpad.net/~camptocamp/ocb-addons/7.0-fix-1319109/+merge/219473
--
https://code.launchpad.net/~camptocamp/ocb-addons/7.0-fix-1319109/+merge/219473
Your team OpenERP Community Backports is requested to review the proposed merge of lp:~camptocamp/ocb-addons/7.0-fix-1319109 into lp:ocb-addons.
=== modified file 'report_webkit/webkit_report.py'
--- report_webkit/webkit_report.py 2014-04-16 07:43:09 +0000
+++ report_webkit/webkit_report.py 2014-05-14 08:43:51 +0000
@@ -37,6 +37,7 @@
import tempfile
import time
import logging
+from functools import partial
from mako.template import Template
from mako.lookup import TemplateLookup
@@ -68,7 +69,6 @@
"""
def __init__(self, name, table, rml=False, parser=False,
header=True, store=False):
- self.parser_instance = False
self.localcontext = {}
report_sxw.__init__(self, name, table, rml, parser,
header, store)
@@ -189,16 +189,16 @@
_logger.error('cannot remove file %s: %s', f_to_del, exc)
return pdf
- def translate_call(self, src):
+ def translate_call(self, parser_instance, src):
"""Translate String."""
- ir_translation = self.pool.get('ir.translation')
+ ir_translation = self.pool['ir.translation']
name = self.tmpl and 'addons/' + self.tmpl or None
- res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid,
- name, 'report', self.parser_instance.localcontext.get('lang', 'en_US'), src)
+ res = ir_translation._get_source(parser_instance.cr, parser_instance.uid,
+ name, 'report', parser_instance.localcontext.get('lang', 'en_US'), src)
if res == src:
# no translation defined, fallback on None (backward compatibility)
- res = ir_translation._get_source(self.parser_instance.cr, self.parser_instance.uid,
- None, 'report', self.parser_instance.localcontext.get('lang', 'en_US'), src)
+ res = ir_translation._get_source(parser_instance.cr, parser_instance.uid,
+ None, 'report', parser_instance.localcontext.get('lang', 'en_US'), src)
if not res :
return src
return res
@@ -213,14 +213,14 @@
if report_xml.report_type != 'webkit':
return super(WebKitParser,self).create_single_pdf(cursor, uid, ids, data, report_xml, context=context)
- self.parser_instance = self.parser(cursor,
+ parser_instance = self.parser(cursor,
uid,
self.name2,
context=context)
self.pool = pooler.get_pool(cursor.dbname)
objs = self.getObjects(cursor, uid, ids, context)
- self.parser_instance.set_context(objs, data, ids, report_xml.report_type)
+ parser_instance.set_context(objs, data, ids, report_xml.report_type)
template = False
@@ -250,18 +250,19 @@
if not css :
css = ''
+ translate_call = partial(self.translate_call, parser_instance)
#default_filters=['unicode', 'entity'] can be used to set global filter
body_mako_tpl = mako_template(template)
helper = WebKitHelper(cursor, uid, report_xml.id, context)
if report_xml.precise_mode:
- objs = self.parser_instance.localcontext['objects']
+ objs = parser_instance.localcontext['objects']
for obj in objs:
- self.parser_instance.localcontext['objects'] = [obj]
+ parser_instance.localcontext['objects'] = [obj]
try :
html = body_mako_tpl.render(helper=helper,
css=css,
- _=self.translate_call,
- **self.parser_instance.localcontext)
+ _=translate_call,
+ **parser_instance.localcontext)
htmls.append(html)
except Exception:
msg = exceptions.text_error_template().render()
@@ -271,8 +272,8 @@
try :
html = body_mako_tpl.render(helper=helper,
css=css,
- _=self.translate_call,
- **self.parser_instance.localcontext)
+ _=translate_call,
+ **parser_instance.localcontext)
htmls.append(html)
except Exception:
msg = exceptions.text_error_template().render()
@@ -282,9 +283,9 @@
try :
head = head_mako_tpl.render(helper=helper,
css=css,
- _=self.translate_call,
+ _=translate_call,
_debug=False,
- **self.parser_instance.localcontext)
+ **parser_instance.localcontext)
except Exception:
raise except_osv(_('Webkit render!'),
exceptions.text_error_template().render())
@@ -294,8 +295,8 @@
try :
foot = foot_mako_tpl.render(helper=helper,
css=css,
- _=self.translate_call,
- **self.parser_instance.localcontext)
+ _=translate_call,
+ **parser_instance.localcontext)
except:
msg = exceptions.text_error_template().render()
_logger.error(msg)
@@ -305,8 +306,8 @@
deb = head_mako_tpl.render(helper=helper,
css=css,
_debug=tools.ustr("\n".join(htmls)),
- _=self.translate_call,
- **self.parser_instance.localcontext)
+ _=translate_call,
+ **parser_instance.localcontext)
except Exception:
msg = exceptions.text_error_template().render()
_logger.error(msg)
Follow ups