mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-19 22:12:03 +02:00
18.0 vanilla
This commit is contained in:
parent
d72e748793
commit
0a7ae8db93
337 changed files with 399651 additions and 232598 deletions
|
|
@ -10,7 +10,7 @@ from werkzeug import urls
|
|||
|
||||
from odoo.tools import safe_eval
|
||||
|
||||
INLINE_TEMPLATE_REGEX = re.compile(r"\{\{(.+?)\}\}")
|
||||
INLINE_TEMPLATE_REGEX = re.compile(r"\{\{(.+?)(\|\|\|\s*(.*?))?\}\}")
|
||||
|
||||
def relativedelta_proxy(*args, **kwargs):
|
||||
# dateutil.relativedelta is an old-style class and cannot be directly
|
||||
|
|
@ -42,33 +42,34 @@ def parse_inline_template(text):
|
|||
for match in INLINE_TEMPLATE_REGEX.finditer(text):
|
||||
literal = text[current_literal_index:match.start()]
|
||||
expression = match.group(1)
|
||||
groups.append((literal, expression))
|
||||
default = match.group(3)
|
||||
groups.append((literal, expression.strip(), default or ''))
|
||||
current_literal_index = match.end()
|
||||
|
||||
# string past last regex match
|
||||
literal = text[current_literal_index:]
|
||||
if literal:
|
||||
groups.append((literal, ''))
|
||||
groups.append((literal, '', ''))
|
||||
|
||||
return groups
|
||||
|
||||
def convert_inline_template_to_qweb(template):
|
||||
template_instructions = parse_inline_template(template or '')
|
||||
preview_markup = []
|
||||
for string, expression in template_instructions:
|
||||
for string, expression, default in template_instructions:
|
||||
if expression:
|
||||
preview_markup.append(Markup('{}<t t-out="{}"/>').format(string, expression))
|
||||
preview_markup.append(Markup('{}<t t-out="{}">{}</t>').format(string, expression, default))
|
||||
else:
|
||||
preview_markup.append(string)
|
||||
return Markup('').join(preview_markup)
|
||||
|
||||
def render_inline_template(template_instructions, variables):
|
||||
results = []
|
||||
for string, expression in template_instructions:
|
||||
for string, expression, default in template_instructions:
|
||||
results.append(string)
|
||||
|
||||
if expression:
|
||||
result = safe_eval.safe_eval(expression, variables)
|
||||
result = safe_eval.safe_eval(expression, variables) or default
|
||||
if result:
|
||||
results.append(str(result))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue