Community mailing list archives

community@mail.odoo.com

Re: Render a html field as qweb

by
Yannik Lieblinger
- 01/22/2016 11:53:34

Hi Paul,

thanks for your great tip. That's what I'm looking for : )!

Your idea works great expect the rendering of the variables. The html code looks really nice, but the variables are rendered as text.

I take the 

 def render_html(self, data=None):

function and overwrite it, so that I can call the get_text function (for rendering the variables and the mako template function) in the qweb template. See below for the complete code:

class ParticularReport(models.AbstractModel):
_name = 'report.sale.report_saleorder'
_template = 'sale.report_saleorder'

def get_text(self):
# For testing. Get the template from the text field.
template = self.env['clb_text.config'].search([('textType', '=', 'pretext')]).text
# try to load the template
try:
template = mako_template_env.from_string(tools.ustr(template))
except Exception:
_logger.exception("Failed to load template %r", template)
return results
variables = {
'ctx': self.env['res.partner'].search([('id', '=', 379)]),
'testVar': 'Test text. Is not shown : (.',
}
try:
render_result = template.render(variables)
except Exception:
_logger.exception("Failed to render template %r using values %r" % (template, variables))
render_result = u""

return render_result

@api.multi
def render_html(self, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name(self._template)

docargs = {
'get_text':self.get_text,
'doc_ids': self._ids,
'doc_model': report.model,
'docs': self,
}

return report_obj.render(self._template, docargs)
And the variable in the text file is defined as: ${ctx.name}, but it only shown as.

I would be really really thankful If you have an idea.

Regards Yannik