From 0777af3e60995cd4aba3b32af60a81a485afd746 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Tue, 13 Sep 2016 11:21:16 +0200 Subject: [PATCH] [IMP] qweb: Add extra condition branching (t-elif) (closes #3b3dbcd) To have the same feature client and server side (t-elif was added in the qWeb client side) --- .../static/lib/qweb/qweb-test-conditionals.xml | 2 -- odoo/addons/base/ir/ir_qweb/qweb.py | 15 +++++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/addons/web/static/lib/qweb/qweb-test-conditionals.xml b/addons/web/static/lib/qweb/qweb-test-conditionals.xml index 782feb24249..e754298a4aa 100644 --- a/addons/web/static/lib/qweb/qweb-test-conditionals.xml +++ b/addons/web/static/lib/qweb/qweb-test-conditionals.xml @@ -16,7 +16,6 @@ -
beginok diff --git a/odoo/addons/base/ir/ir_qweb/qweb.py b/odoo/addons/base/ir/ir_qweb/qweb.py index e2f877dfadf..ad0aaaa5f88 100644 --- a/odoo/addons/base/ir/ir_qweb/qweb.py +++ b/odoo/addons/base/ir/ir_qweb/qweb.py @@ -682,7 +682,7 @@ class QWeb(object): """ return [ 'debug', - 'groups', 'foreach', 'if', 'else', + 'groups', 'foreach', 'if', 'elif', 'else', 'field', 'esc', 'raw', 'tag', 'call', @@ -947,10 +947,21 @@ class QWeb(object): el.attrib['t-else'] = '_t_skip_else_' return compiled + def _compile_directive_elif(self, el, options): + _elif = el.attrib.pop('t-elif') + if _elif == '_t_skip_else_': + return [] + if not options.pop('t_if', None): + raise ValueError("t-elif directive must be preceded by t-if directive") + el.attrib['t-if'] = _elif + compiled = self._compile_directive_if(el, options) + el.attrib['t-elif'] = '_t_skip_else_' + return compiled + def _compile_directive_if(self, el, options): orelse = [] next_el = el.getnext() - if next_el is not None and 't-else' in next_el.attrib: + if next_el is not None and {'t-else', 't-elif'} & set(next_el.attrib.keys()): if el.tail and not el.tail.isspace(): raise ValueError("Unexpected non-whitespace characters between t-if and t-else directives") el.tail = None