Skip to content

Commit

Permalink
[FIX] Report: translation fixed, use of 'primary clone' of web.layout…
Browse files Browse the repository at this point in the history
… and website.layout, minimal template is now a QWeb template
  • Loading branch information
sle-odoo committed Jun 27, 2014
1 parent 195fa93 commit fc8592a
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 160 deletions.
7 changes: 6 additions & 1 deletion addons/report/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ def report_routes(self, reportname, docids=None, converter=None, **data):
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)
Expand Down
34 changes: 10 additions & 24 deletions addons/report/models/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@
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__)
Expand Down Expand Up @@ -71,23 +69,6 @@ class Report(osv.Model):

public_user = None

MINIMAL_HTML_PAGE = """
<base href="{base_url}">
<!DOCTYPE html>
<html style="height: 0;">
<head>
<link href="/report/static/src/css/reset.min.css" rel="stylesheet"/>
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<style type='text/css'>{css}</style>
{subst}
</head>
<body class="container" onload="subst()">
{body}
</body>
</html>"""

#--------------------------------------------------------------------------
# Extension of ir_ui_view.render with arguments frequently used in reports
#--------------------------------------------------------------------------
Expand Down Expand Up @@ -134,6 +115,7 @@ def translate_doc(doc_id, model, lang_field, template):
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,
Expand Down Expand Up @@ -198,6 +180,10 @@ def get_pdf(self, cr, uid, ids, report_name, html=None, data=None, context=None)
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:
Expand All @@ -208,12 +194,12 @@ def get_pdf(self, cr, uid, ids, report_name, html=None, data=None, context=None)

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']"):
Expand All @@ -230,7 +216,7 @@ def get_pdf(self, cr, uid, ids, report_name, html=None, data=None, context=None)
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
Expand Down
94 changes: 46 additions & 48 deletions addons/report/views/layouts.xml
Original file line number Diff line number Diff line change
@@ -1,55 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="html_container">
&lt;!DOCTYPE html&gt;
<html t-att-lang="lang and lang.replace('_', '-')"
t-att-data-editable="'1' if editable else None"
t-att-data-view-xmlid="xmlid if editable else None"
t-att-data-main-object="repr(main_object) if editable else None"
t-att-data-report-margin-top="data_report_margin_top if data_report_margin_top else None"
t-att-data-report-header-spacing="data_report_header_spacing if data_report_header_spacing else None"
t-att-data-report-dpi="data_report_dpi if data_report_dpi else None"
t-att-data-oe-company-name="res_company.name">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>

<t t-if="main_object and 'website_meta_title' in main_object">
<t t-set="title" t-value="main_object.website_meta_title"/>
</t>
<t t-if="not title and main_object and 'name' in main_object">
<t t-set="additional_title" t-value="main_object.name"/>
</t>
<meta name="description" t-att-value="main_object and 'website_meta_description' in main_object
and main_object.website_meta_description or website_meta_description"/>
<meta name="keywords" t-att-value="main_object and 'website_meta_keywords' in main_object
and main_object.website_meta_keywords or website_meta_keywords"/>

<link id="bootstrap_css" rel='stylesheet' href='/web/static/lib/bootstrap/css/bootstrap.css' t-ignore="true"/>
<link rel="stylesheet" type="text/css" href='/website/static/src/css/website.css'/>
<style type="text/css">
<t t-call="report.style"/>
</style>

<link rel='stylesheet' href='/web/static/lib/fontawesome/css/font-awesome.css'/>
<template id="layout" inherit_id="web.layout" primary="True">
<!-- Add report attributes -->
<xpath expr="//html" position="attributes">
<attribute name="t-att-data-report-margin-top">data_report_margin_top if data_report_margin_top else None</attribute>
<attribute name="t-att-data-report-header-spacing">data_report_header_spacing if data_report_header_spacing else None</attribute>
<attribute name="t-att-data-report-dpi">data_report_dpi if data_report_dpi else None</attribute>
</xpath>
<!-- Add report style -->
<xpath expr="//head" position="inside">
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<style type="text/css">
<t t-call="report.style"/>
</style>
</xpath>
<!-- Remove conflicting style -->
<xpath expr="//head/link[@href='/web/static/src/css/full.css']" position="replace"></xpath>
<!-- Correct view inheritance -->
<xpath expr="//t[@t-name='web.layout']" position="attributes">
<attribute name="t-name">report.layout</attribute>
</xpath>
</template>

<script type="text/javascript" src="/web/static/lib/es5-shim/es5-shim.min.js"></script>
<script type="text/javascript" src="/web/static/lib/underscore/underscore.js"></script>
<script type="text/javascript" src="/web/static/lib/underscore.string/lib/underscore.string.js"></script>
<script type="text/javascript" src="/web/static/lib/jquery/jquery.js"></script>
<script type="text/javascript" src="/web/static/lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="/web/static/lib/qweb/qweb2.js"></script>
<script type="text/javascript" src="/web/static/src/js/openerpframework.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.js"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.snippets.animation.js"></script>
<t t-raw="head or ''" name='layout_head'/>
</head>
<body class="container">
<div id="wrapwrap">
<t t-raw="0"/>
</div>
</body>
</html>
<template id="html_container">
<t t-set="body_classname" t-value="'container'"/>
<t t-call="report.layout">
<t t-raw="0"/>
</t>
</template>

<template id="style">
Expand Down Expand Up @@ -164,5 +144,23 @@
<t t-raw="0" />
</template>

<template id="minimal_layout">
<t t-raw="'&lt;base href=%s&gt;' % base_url"/>
&lt;!DOCTYPE html&gt;
<html style="height: 0;">
<head>
<link href="/report/static/src/css/reset.min.css" rel="stylesheet"/>
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<style type='text/css'><t t-raw="css"/></style>
<t t-raw="subst"/>
</head>
<body class="container" onload="subst()">
<t t-raw="body"/>
</body>
</html>
</template>

</data>
</openerp>
2 changes: 1 addition & 1 deletion addons/sale/views/report_saleorder.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
<tbody class="sale_tbody">
<tr t-foreach="o.order_line" t-as="l">
<td>
<span t-field="l.name"/>
<span t-field="l.name"/>
</td>
<td>
<span t-esc="', '.join(map(lambda x: x.name, l.tax_id))"/>
Expand Down
10 changes: 5 additions & 5 deletions addons/website/views/website_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@

<template id="layout" name="Main layout">&lt;!DOCTYPE html&gt;
<html t-att-lang="lang and lang.replace('_', '-')"
t-att-data-website-id="website.id if editable else None"
t-att-data-website-id="website.id if editable and website else None"
t-att-data-editable="'1' if editable else None"
t-att-data-editable-no-editor="editable_no_editor or None"
t-att-data-translatable="'1' if translatable else None"
Expand All @@ -82,10 +82,10 @@
and main_object.website_meta_keywords or website_meta_keywords"/>
<title><t t-esc="title"/></title>

<t t-set="languages" t-value="website.get_languages()"/>
<t t-if="request.website_multilang">
<t t-set="languages" t-value="website.get_languages() if website else None"/>
<t t-if="request and request.website_multilang">
<t t-foreach="languages" t-as="lg">
<t t-set="force_lang" t-value="lg[0] if lg[0] != website.default_lang_code else None"/>
<t t-set="force_lang" t-value="lg[0] if website and lg[0] != website.default_lang_code else None"/>
<link rel="alternate" t-att-href="url_for(request.httprequest.path + '?' + keep_query(), lang=force_lang)" t-att-hreflang="lg[0].replace('_', '-').lower()" />
</t>
</t>
Expand Down Expand Up @@ -150,7 +150,7 @@
</div>
</footer>
</div>
<t t-if="website.google_analytics_key">
<t t-if="website and website.google_analytics_key">
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
Expand Down
2 changes: 1 addition & 1 deletion addons/website_livechat/views/website_livechat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<template id="header" inherit_id="website.layout" name="LiveChat Snippet">
<xpath expr="//body" position="inside">
<t t-if="website.channel_id">
<t t-if="website and website.channel_id">
<t t-raw="website.channel_id.script"/>
</t>
</xpath>
Expand Down
Loading

0 comments on commit fc8592a

Please sign in to comment.