Major changes:
- Remove some of the recursively when compiling
- Compile attributes became a directive
- Compile options became a directive
- `t-field` compilation now uses the same logic as `t-out`
- Simplification of ``t-if`` directive compilation
- Improved handling of errors wrapped by QWebException
- Constants defined outside the class
Odoo
┗━► _render (returns MarkupSafe)
┗━► _compile (returns function) ◄━━━━━━━━━━┓
┗━► _compile_node (returns code string array) ◄━━━━━━━━┓ ┃
┃ (skip the current node if found t-qweb-skip) ┃ ┃
┃ (add technical directives: t-tag-open, t-tag-close, t-inner-content) ┃ ┃
┃ ┃ ┃
┣━► _directives_eval_order (defined directive order) ┃ ┃
┣━► _compile_directives (loop) Consume all remaining directives ◄━━━┓ ┃ ┃
┃ ┃ (e.g.: to change the indentation) ┃ ┃ ┃
┃ ┣━► _compile_directive ┃ ┃ ┃
┃ ┃ ┗━► t-if ━━► _compile_directive_if ━┫ ┃ ┃
┃ ┃ ┗━► t-foreach ━━► _compile_directive_foreach ━┛ ┃ ┃
┃ ┃ ┗━► t-inner-content ━━► _compile_directive_inner_content ◄━━━━━┓ ━┛ ┃
┃ ┃ ┗━► t-options ━━► _compile_directive_options ┃ ┃
┃ ┃ ┗━► t-call ━━► _compile_directive_call ━┫ ━━━┛
┃ ┃ ┗━► t-att ━━► _compile_directive_att ┃
┃ ┃ ┗━► t-tag-open ━━► _compile_directive_open ◄━━┓ ┃
┃ ┃ ┗━► t-tag-close ━━► _compile_directive_close ◄━━┫ ┃
┃ ┃ ┗━► t-out ━━► _compile_directive_out ━┛ ━┫ ◄━━┓
┃ ┃ ┗━► t-field ━━► _compile_directive_field ┃ ━┫
┃ ┃ ┗━► t-esc ━━► _compile_directive_esc ┃ ━┛
┃ ┃ ┗━► t-* ━━► ... ┃
┃ ┃ ┃
┗━━┻━► _compile_static_node ━┛
closes odoo/odoo#81024
Related: odoo/enterprise#22942
Signed-off-by: Christophe Monniez (moc) <moc@odoo.com>
17 lines
598 B
Python
17 lines
598 B
Python
# -*- coding: utf-8 -*-
|
|
from odoo import models
|
|
|
|
class IrQweb(models.AbstractModel):
|
|
""" Add ``raise_on_code`` option for qweb. When this option is activated
|
|
then all directives are prohibited.
|
|
"""
|
|
_inherit = 'ir.qweb'
|
|
|
|
def _get_template_cache_keys(self):
|
|
return super()._get_template_cache_keys() + ['raise_on_code']
|
|
|
|
def _compile_directives(self, el, options, indent):
|
|
if options.get('raise_on_code'):
|
|
raise PermissionError("This rendering mode prohibits the use of directives.")
|
|
return super()._compile_directives(el, options, indent)
|