[IMP] ir_ui_view: allow to use a minimal evaluation context when rendering QWeb
Currently some base context used for evaluation is computed when rendering QWeb templates. Evaluation context is build in base and improved notably in website module. This commit adds an option to skip this context build and have a minimal evaluation context based on given values. Purpose is to avoid having to search and browse unnecessary content when evaluating some custom templates. When we know precisely what we need when rendering a template there is no need to add unnecessary items in the evaluation context. This commit is related to task ID 1817951. Closes #23291 .
This commit is contained in:
@@ -16,7 +16,7 @@ class IrUiView(models.Model):
|
||||
_inherit = 'ir.ui.view'
|
||||
|
||||
@api.multi
|
||||
def render(self, values=None, engine='ir.qweb'):
|
||||
def render(self, values=None, engine='ir.qweb', minimal_qcontext=False):
|
||||
if values and values.get('editable'):
|
||||
try:
|
||||
self.check_access_rights('write')
|
||||
@@ -24,7 +24,7 @@ class IrUiView(models.Model):
|
||||
except AccessError:
|
||||
values['editable'] = False
|
||||
|
||||
return super(IrUiView, self).render(values=values, engine=engine)
|
||||
return super(IrUiView, self).render(values=values, engine=engine, minimal_qcontext=minimal_qcontext)
|
||||
|
||||
#------------------------------------------------------
|
||||
# Save from html
|
||||
|
||||
@@ -97,7 +97,7 @@ class View(models.Model):
|
||||
return super(View, self).get_view_id(xml_id)
|
||||
|
||||
@api.multi
|
||||
def render(self, values=None, engine='ir.qweb'):
|
||||
def render(self, values=None, engine='ir.qweb', minimal_qcontext=False):
|
||||
""" Render the template. If website is enabled on request, then extend rendering context with website values. """
|
||||
new_context = dict(self._context)
|
||||
if request and getattr(request, 'is_frontend', False):
|
||||
@@ -115,7 +115,7 @@ class View(models.Model):
|
||||
|
||||
if self._context != new_context:
|
||||
self = self.with_context(new_context)
|
||||
return super(View, self).render(values, engine=engine)
|
||||
return super(View, self).render(values, engine=engine, minimal_qcontext=minimal_qcontext)
|
||||
|
||||
@api.model
|
||||
def _prepare_qcontext(self):
|
||||
|
||||
@@ -1154,10 +1154,10 @@ actual arch.
|
||||
return self.browse(self.get_view_id(template)).render(values, engine)
|
||||
|
||||
@api.multi
|
||||
def render(self, values=None, engine='ir.qweb'):
|
||||
def render(self, values=None, engine='ir.qweb', minimal_qcontext=False):
|
||||
assert isinstance(self.id, pycompat.integer_types)
|
||||
|
||||
qcontext = self._prepare_qcontext()
|
||||
qcontext = dict() if minimal_qcontext else self._prepare_qcontext()
|
||||
qcontext.update(values or {})
|
||||
|
||||
return self.env[engine].render(self.id, qcontext)
|
||||
|
||||
Reference in New Issue
Block a user