[IMP] Independance from the website module: moved the editor into a 'website_report' module

bzr revid: sle@openerp.com-20140219105327-xx2jaqu4dvhv5goh
This commit is contained in:
Simon Lejeune 2014-02-19 11:53:27 +01:00
parent e671171ed8
commit 1be06b0a67
7 changed files with 128 additions and 83 deletions

View File

@ -1,13 +1,13 @@
{
'name': 'Report',
'category': 'Website',
'category': 'Base',
'summary': 'Report',
'version': '1.0',
'description': """
Report
""",
'author': 'OpenERP SA',
'depends': ['base', 'website'],
'depends': ['base'],
'data': [
'views/layouts.xml',
'views/paperformat_view.xml',
@ -19,4 +19,5 @@ Report
'static/src/js/qwebactionmanager.js',
],
'installable': True,
'auto_install': True,
}

View File

@ -1,3 +1,2 @@
import report
import report_paperformat

View File

@ -131,6 +131,12 @@ class report(osv.Model):
return res
def render(self, cr, uid, ids, template, values=None, context=None):
"""Allow to render a QWeb template python-side. This function returns the 'ir.ui.view'
render but embellish it with some variables/methods used in reports.
:param values: additionnal methods/variables used in the rendering
:returns: html representation of the template
"""
if values is None:
values = {}
@ -146,6 +152,8 @@ class report(osv.Model):
}
self._get_lang_dict()
view_obj = self.pool['ir.ui.view']
def render_doc(doc_id, model, template):
"""Helper used when a report should be translated into the associated
partner's lang.
@ -160,9 +168,8 @@ class report(osv.Model):
"""
ctx = context.copy()
doc = self.pool[model].browse(cr, uid, doc_id, context=ctx)
view_obj = self.pool['ir.ui.view']
qcontext = values.copy()
# Do not force-translate if we chose to display to report in a specific lang
# Do not force-translate if we chose to display the report in a specific lang
if ctx.get('translatable') is True:
qcontext['o'] = doc
else:
@ -171,18 +178,33 @@ class report(osv.Model):
return view_obj.render(cr, uid, template, qcontext, context=ctx)
current_user = self.pool['res.users'].browse(cr, uid, uid, context=context)
# Website independance code
website = False
res_company = current_user.company_id
try:
website = request.website
res_company = request.website.company_id
except:
pass
values.update({
'time': time,
'user': current_user,
'user_id': current_user.id,
'formatLang': self.formatLang,
'get_digits': self.get_digits,
'render_doc': render_doc,
'website': website,
'res_company': res_company,
})
return request.website.render(template, values)
return view_obj.render(cr, uid, template, values, context=context)
def get_pdf(self, report, record_id, context=None):
"""Used to return content of a generated PDF.
"""Used to return the content of a generated PDF.
:returns: pdf
"""

View File

@ -50,15 +50,6 @@
</head>
<body class="container">
<div id="wrapwrap">
<t t-set="languages" t-value="website.get_languages()"/>
<ul class="list-inline js_language_selector mt16" t-if="(len(languages) &gt; 1 or editable)">
<li t-foreach="languages" t-as="lg">
<a t-att-href="url_for('', lang=lg[0]) + '?' + keep_query()"
t-att-data-default-lang="editable and 'true' if lg[0] == website.default_lang_code else None">
<t t-esc="lg[1].split('/').pop()"/>
</a>
</li>
</ul>
<t t-raw="0"/>
</div>
</body>
@ -120,14 +111,14 @@
<ul class="list-inline">
<li t-if="company.phone">Phone: <span t-field="company.phone"/></li>
<li t-if="company.fax">&amp;bull;</li>
<li t-if="company.fax and company.phone">&amp;bull;</li>
<li t-if="company.fax">Fax: <span t-field="company.fax"/></li>
<li t-if="company.email">&amp;bull;</li>
<li t-if="company.email">Email: <span t-field="company.email"/></li>
<li t-if="website.name">&amp;bull;</li>
<li t-if="website.name">Website: <span t-esc="website.name"/></li>
<li t-if="website">&amp;bull;</li>
<li t-if="website">Website: <span t-esc="website.name"/></li>
<br/>
<li><span t-field="company.rml_footer"/></li>
<li t-if="company.rml_footer">|</li>
@ -169,69 +160,5 @@
</div>
<t t-raw="0" />
</template>
<template id="editor_head" inherit_id="report.html_container" name="Editor" groups="base.group_website_publisher">
<xpath expr="//body" position="attributes">
<attribute name="style">padding-top: 51px;</attribute>
</xpath>
<xpath expr="//body" position="inside">
<div id="website-top-navbar-placeholder" class="navbar navbar-inverse navbar-fixed-top hidden-xs">
<div class="navbar-header">
<form class="navbar-form navbar-left">
<button type="button" class="btn btn-primary">Edit</button>
</form>
</div>
<div class="collapse navbar-collapse navbar-edit-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" onclick="return false;"><i class="fa fa-mobile" title="Mobile preview"/></a></li>
<li class="divider-vertical"/>
<li><a href="#" onclick="return false;"><span title="Promote page on the web">Promote</span></a></li>
<li class="dropdown">
<a href="#" onclick="return false;">Content <span class="caret"/></a>
</li>
<li class="dropdown">
<a href="#" onclick="return false;">Customize <span class="caret"/></a>
</li>
<li class="dropdown">
<a href="#" onclick="return false;">Help <span class="caret"/></a>
</li>
</ul>
</div>
</div>
</xpath>
<xpath expr='//t[@name="layout_head"]' position="before">
<link rel='stylesheet' href='/website/static/src/css/snippets.css'/>
<link rel='stylesheet' href='/website/static/src/css/editor.css'/>
<link rel='stylesheet' href='/website/static/lib/bootstrap-tour/bootstrap-tour.css'/>
<link rel="stylesheet" href="/web/static/lib/select2/select2.css"/>
<link rel="stylesheet" href="/website/static/lib/select2-bootstrap-css/select2-bootstrap.css"/>
<link rel='stylesheet' href="/web/static/lib/jquery.ui/css/smoothness/jquery-ui-1.9.1.custom.css"/>
<script type="text/javascript" src="/web/static/lib/select2/select2.js"></script>
<script type="text/javascript" src="/web/static/lib/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/website/static/lib/bootstrap-tour/bootstrap-tour.js"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/lib/ace/ace.js"></script>
<script type="text/javascript" src="/website/static/lib/vkbeautify/vkbeautify.0.99.00.beta.js"></script>
<script type="text/javascript" src="/web/static/lib/jquery.ui/js/jquery-ui-1.9.1.custom.js"></script>
<!-- mutation observers shim backed by mutation events (8 < IE < 11, Safari < 6, FF < 14, Chrome < 17) -->
<script type="text/javascript" src="/website/static/lib//jquery.mjs.nestedSortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/website/static/lib/MutationObservers/test/sidetable.js"></script>
<script type="text/javascript" src='/website/static/lib/nearest/jquery.nearest.js'></script>
<script type="text/javascript" src="/website/static/lib/MutationObservers/MutationObserver.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.editor.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.editor.newpage.js" groups="base.group_website_designer"></script>
<script type="text/javascript" src="/website/static/src/js/website.menu.js" groups="base.group_website_designer"></script>
<script type="text/javascript" src="/website/static/src/js/website.mobile.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.seo.js"></script>
<script type="text/javascript" id="website_tour_js" src="/website/static/src/js/website.tour.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.tour.banner.js" groups="base.group_website_designer"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.snippets.editor.js"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.ace.js"></script>
<script t-if="translatable" type="text/javascript" src="/website/static/src/js/website.translator.js"></script>
</xpath>
</template>
</data>
</openerp>

View File

View File

@ -0,0 +1,16 @@
{
'name': 'Website Report',
'category': 'Website',
'summary': 'Website Editor on reports',
'version': '1.0',
'description': """
Use the website editor to customize your reports.
""",
'author': 'OpenERP SA',
'depends': ['base', 'website', 'report'],
'data': [
'views/layouts.xml',
],
'installable': True,
'auto_install': True,
}

View File

@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="editor_head" inherit_id="report.html_container" name="Editor" groups="base.group_website_publisher">
<xpath expr="//body" position="attributes">
<attribute name="style">padding-top: 51px;</attribute>
</xpath>
<xpath expr="//body" position="inside">
<div id="website-top-navbar-placeholder" class="navbar navbar-inverse navbar-fixed-top hidden-xs">
<div class="navbar-header">
<form class="navbar-form navbar-left">
<button type="button" class="btn btn-primary">Edit</button>
</form>
</div>
<div class="collapse navbar-collapse navbar-edit-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" onclick="return false;"><i class="fa fa-mobile" title="Mobile preview"/></a></li>
<li class="divider-vertical"/>
<li><a href="#" onclick="return false;"><span title="Promote page on the web">Promote</span></a></li>
<li class="dropdown">
<a href="#" onclick="return false;">Content <span class="caret"/></a>
</li>
<li class="dropdown">
<a href="#" onclick="return false;">Customize <span class="caret"/></a>
</li>
<li class="dropdown">
<a href="#" onclick="return false;">Help <span class="caret"/></a>
</li>
</ul>
</div>
</div>
</xpath>
<xpath expr='//t[@name="layout_head"]' position="before">
<link rel='stylesheet' href='/website/static/src/css/snippets.css'/>
<link rel='stylesheet' href='/website/static/src/css/editor.css'/>
<link rel='stylesheet' href='/website/static/lib/bootstrap-tour/bootstrap-tour.css'/>
<link rel="stylesheet" href="/web/static/lib/select2/select2.css"/>
<link rel="stylesheet" href="/website/static/lib/select2-bootstrap-css/select2-bootstrap.css"/>
<link rel='stylesheet' href="/web/static/lib/jquery.ui/css/smoothness/jquery-ui-1.9.1.custom.css"/>
<script type="text/javascript" src="/web/static/lib/select2/select2.js"></script>
<script type="text/javascript" src="/web/static/lib/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/website/static/lib/bootstrap-tour/bootstrap-tour.js"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/lib/ace/ace.js"></script>
<script type="text/javascript" src="/website/static/lib/vkbeautify/vkbeautify.0.99.00.beta.js"></script>
<script type="text/javascript" src="/web/static/lib/jquery.ui/js/jquery-ui-1.9.1.custom.js"></script>
<!-- mutation observers shim backed by mutation events (8 < IE < 11, Safari < 6, FF < 14, Chrome < 17) -->
<script type="text/javascript" src="/website/static/lib//jquery.mjs.nestedSortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/website/static/lib/MutationObservers/test/sidetable.js"></script>
<script type="text/javascript" src='/website/static/lib/nearest/jquery.nearest.js'></script>
<script type="text/javascript" src="/website/static/lib/MutationObservers/MutationObserver.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.editor.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.editor.newpage.js" groups="base.group_website_designer"></script>
<script type="text/javascript" src="/website/static/src/js/website.menu.js" groups="base.group_website_designer"></script>
<script type="text/javascript" src="/website/static/src/js/website.mobile.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.seo.js"></script>
<script type="text/javascript" id="website_tour_js" src="/website/static/src/js/website.tour.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.tour.banner.js" groups="base.group_website_designer"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.snippets.editor.js"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.ace.js"></script>
<script t-if="translatable" type="text/javascript" src="/website/static/src/js/website.translator.js"></script>
</xpath>
<xpath expr='//body[@class="container"]/div[@id="wrapwrap"]' position="before">
<t t-set="languages" t-value="website.get_languages()"/>
<ul class="list-inline js_language_selector mt16" t-if="(len(languages) &gt; 1 or editable)">
<li t-foreach="languages" t-as="lg">
<a t-att-href="url_for('', lang=lg[0]) + '?' + keep_query()"
t-att-data-default-lang="editable and 'true' if lg[0] == website.default_lang_code else None">
<t t-esc="lg[1].split('/').pop()"/>
</a>
</li>
</ul>
</xpath>
</template>
</data>
</openerp>