From fc8592adf2f26bf35007d6cc625fb2005cd65b5d Mon Sep 17 00:00:00 2001 From: Simon Lejeune Date: Fri, 27 Jun 2014 12:00:49 +0200 Subject: [PATCH] [FIX] Report: translation fixed, use of 'primary clone' of web.layout and website.layout, minimal template is now a QWeb template --- addons/report/controllers/main.py | 7 +- addons/report/models/report.py | 34 ++---- addons/report/views/layouts.xml | 94 +++++++------- addons/sale/views/report_saleorder.xml | 2 +- addons/website/views/website_templates.xml | 10 +- .../views/website_livechat.xml | 2 +- addons/website_report/views/layouts.xml | 115 ++++++------------ 7 files changed, 104 insertions(+), 160 deletions(-) diff --git a/addons/report/controllers/main.py b/addons/report/controllers/main.py index c6bc13d38f8..01992d64c60 100644 --- a/addons/report/controllers/main.py +++ b/addons/report/controllers/main.py @@ -50,7 +50,12 @@ class ReportController(Controller): if data.get('options'): options_data = simplejson.loads(data['options']) if data.get('context'): - context.update(simplejson.loads(data['context'])) + # Ignore 'lang' here, because the context in data is the one from the webclient *but* if + # the user explicitely wants to change the lang, this mechanism overwrites it. + data_context = simplejson.loads(data['context']) + if data_context.get('lang'): + del data_context['lang'] + context.update(data_context) if converter == 'html': html = report_obj.get_html(cr, uid, docids, reportname, data=options_data, context=context) diff --git a/addons/report/models/report.py b/addons/report/models/report.py index 17635688063..3e4bbb069e1 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -34,10 +34,8 @@ import lxml.html import cStringIO import subprocess from distutils.version import LooseVersion -try: - from pyPdf import PdfFileWriter, PdfFileReader -except ImportError: - PdfFileWriter = PdfFileReader = None +from functools import partial +from pyPdf import PdfFileWriter, PdfFileReader _logger = logging.getLogger(__name__) @@ -71,23 +69,6 @@ class Report(osv.Model): public_user = None - MINIMAL_HTML_PAGE = """ - - - - - - - - - - {subst} - - - {body} - -""" - #-------------------------------------------------------------------------- # Extension of ir_ui_view.render with arguments frequently used in reports #-------------------------------------------------------------------------- @@ -134,6 +115,7 @@ class Report(osv.Model): website = None if request and hasattr(request, 'website'): website = request.website + context.update(translatable=context.get('lang') != request.website.default_lang_code) values.update( time=time, translate_doc=translate_doc, @@ -198,6 +180,10 @@ class Report(osv.Model): footerhtml = [] base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') + # Minimal page renderer + view_obj = self.pool['ir.ui.view'] + render_minimal = partial(view_obj.render, cr, uid, 'report.minimal_layout', context=context) + # The received html report must be simplified. We convert it in a xml tree # in order to extract headers, bodies and footers. try: @@ -208,12 +194,12 @@ class Report(osv.Model): for node in root.xpath("//div[@class='header']"): body = lxml.html.tostring(node) - header = self.MINIMAL_HTML_PAGE.format(css=css, subst=subst, body=body, base_url=base_url) + header = render_minimal(dict(css=css, subst=subst, body=body, base_url=base_url)) headerhtml.append(header) for node in root.xpath("//div[@class='footer']"): body = lxml.html.tostring(node) - footer = self.MINIMAL_HTML_PAGE.format(css=css, subst=subst, body=body, base_url=base_url) + footer = render_minimal(dict(css=css, subst=subst, body=body, base_url=base_url)) footerhtml.append(footer) for node in root.xpath("//div[@class='page']"): @@ -230,7 +216,7 @@ class Report(osv.Model): reportid = False body = lxml.html.tostring(node) - reportcontent = self.MINIMAL_HTML_PAGE.format(css=css, subst='', body=body, base_url=base_url) + reportcontent = render_minimal(dict(css=css, subst='', body=body, base_url=base_url)) # FIXME: imo the best way to extract record id from html reports is by using the # qweb branding. As website editor is not yet splitted in a module independant from diff --git a/addons/report/views/layouts.xml b/addons/report/views/layouts.xml index f9c0ea7ef73..f12f7672d21 100644 --- a/addons/report/views/layouts.xml +++ b/addons/report/views/layouts.xml @@ -1,55 +1,35 @@ + + + + diff --git a/addons/sale/views/report_saleorder.xml b/addons/sale/views/report_saleorder.xml index 5c198c635a3..a6771823f55 100644 --- a/addons/sale/views/report_saleorder.xml +++ b/addons/sale/views/report_saleorder.xml @@ -65,7 +65,7 @@ - + diff --git a/addons/website/views/website_templates.xml b/addons/website/views/website_templates.xml index 4a37ae180fc..4b31b086dbd 100644 --- a/addons/website/views/website_templates.xml +++ b/addons/website/views/website_templates.xml @@ -57,7 +57,7 @@