# HG changeset patch # User Goffi # Date 1509921405 -3600 # Node ID 5425cf18929b37042bc590561251561285c062ff # Parent b7e24ce97a06e83adee3cc4103f389740f645df9 template: fixed the use of eval_context_filter in item_filter diff -r b7e24ce97a06 -r 5425cf18929b src/tools/common/template.py --- a/src/tools/common/template.py Sun Nov 05 20:34:51 2017 +0100 +++ b/src/tools/common/template.py Sun Nov 05 23:36:45 2017 +0100 @@ -427,7 +427,8 @@ continue return u' '.join(classes) or None - def _item_filter(self, item, filters): + @jinja2.contextfilter + def _item_filter(self, ctx, item, filters): """return item's value, filtered if suitable @param item(object): item to filter @@ -446,14 +447,28 @@ if filter_ is None: return value elif isinstance(filter_, dict): - filter_args = filter_.get(u'filter_args') + filters_args = filter_.get(u'filters_args') for idx, f_name in enumerate(filter_.get(u'filters', [])): - kwargs = filter_args[idx] if filter_args is not None else {} - value = self.env.filters[f_name](value, **kwargs) - template = filter_.get(u'template', u'{value}') - return template.format(value=value) - else: - return filter_(item.value) + kwargs = filters_args[idx] if filters_args is not None else {} + filter_func = self.env.filters[f_name] + try: + eval_context_filter = filter_func.evalcontextfilter + except AttributeError: + eval_context_filter = False + + if eval_context_filter: + value = filter_func(ctx.eval_ctx, value, **kwargs) + else: + value = filter_func(value, **kwargs) + template = filter_.get(u'template') + if template: + # format will return a string, so we need to check first + # if the value is safe or not, and re-mark it after formatting + is_safe = isinstance(value, safe) + value = template.format(value=value) + if is_safe: + value = safe(value) + return value def _adv_format(self, value, template, **kwargs): """Advancer formatter