[FIX] ir_qweb: send template options in context to the fields

Application of a fix more specific to the problem of the contact widget
which can not serialize the dictionary because it contains the values of
the context of which browse record. (because contact try to
json.dumps options for multi-edition feature in web_editor)

opw-1859848

https://github.com/odoo/odoo/commit/ab85e9594651fd33ffd2747f4d3c5b360e7c7922
This commit is contained in:
Christophe Matthieu
2018-06-27 15:11:37 +02:00
parent 787a156f0d
commit 39f0f5db77
4 changed files with 9 additions and 20 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ class Image(models.AbstractModel):
atts["data-zoom"] = src_zoom and u'1' or None
atts["data-zoom-image"] = src_zoom
atts = self.env['ir.qweb']._post_processing_att('img', atts, options)
atts = self.env['ir.qweb']._post_processing_att('img', atts, options.get('template_options'))
img = ['<img']
for name, value in atts.items():
+1
View File
@@ -173,6 +173,7 @@ class Contact(models.AbstractModel):
@api.model
def attributes(self, record, field_name, options, values):
attrs = super(Contact, self).attributes(record, field_name, options, values)
options.pop('template_options') # remove options not specific to this widget
attrs['data-oe-contact-options'] = json.dumps(options)
return attrs
+2 -2
View File
@@ -261,7 +261,7 @@ class HTMLConverter(models.AbstractModel):
for element in body.iter():
if element.attrib:
attrib = OrderedDict(element.attrib)
attrib = irQweb._post_processing_att(element.tag, attrib, options)
attrib = irQweb._post_processing_att(element.tag, attrib, options.get('template_options'))
element.attrib.clear()
element.attrib.update(attrib)
return etree.tostring(body, encoding='unicode', method='html')[6:-7]
@@ -488,7 +488,7 @@ class Contact(models.AbstractModel):
'object': value,
'options': options
}
return self.env['ir.qweb'].render('base.contact', val)
return self.env['ir.qweb'].render('base.contact', val, **options.get('template_options'))
class QwebView(models.AbstractModel):
+5 -17
View File
@@ -51,21 +51,7 @@ class IrQWeb(models.AbstractModel, QWeb):
if method.startswith('render_'):
_logger.warning("Unused method '%s' is found in ir.qweb." % method)
def jsonable(val):
try:
json.dumps(val)
return True
except Exception:
return False
context = {
key: val
for key, val in self.env.context.items()
if isinstance(key, pycompat.string_types) and not key.startswith('_')
if jsonable(val)
}
context['dev_mode'] = 'qweb' in tools.config['dev_mode']
# context = dict(self.env.context, dev_mode='qweb' in tools.config['dev_mode'])
context = dict(self.env.context, dev_mode='qweb' in tools.config['dev_mode'])
context.update(options)
return super(IrQWeb, self).render(id_or_xml_id, values=values, **context)
@@ -369,8 +355,7 @@ class IrQWeb(models.AbstractModel, QWeb):
field = record._fields[field_name]
# adds template compile options for rendering fields
for k, v in options.items():
field_options.setdefault(k, v)
field_options['template_options'] = options
# adds generic field options
field_options['tagName'] = tagName
@@ -392,6 +377,9 @@ class IrQWeb(models.AbstractModel, QWeb):
return (attributes, content, inherit_branding or translate)
def _get_widget(self, value, expression, tagName, field_options, options, values):
# adds template compile options for rendering fields
field_options['template_options'] = options
field_options['type'] = field_options['widget']
field_options['tagName'] = tagName
field_options['expression'] = expression