Mercurial > libervia-backend
diff sat/tools/common/template.py @ 2675:39d187f3698d
template: import contextfilter as module attribute
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 18 Sep 2018 20:55:58 +0200 |
parents | 0fa217fafabf |
children | da8f3ac86845 |
line wrap: on
line diff
--- a/sat/tools/common/template.py Tue Sep 18 20:53:50 2018 +0200 +++ b/sat/tools/common/template.py Tue Sep 18 20:55:58 2018 +0200 @@ -59,6 +59,7 @@ from jinja2 import is_undefined from jinja2 import utils from jinja2 import TemplateNotFound +from jinja2 import contextfilter from jinja2.loaders import split_template_path from lxml import etree @@ -327,7 +328,6 @@ Only set to True if environment is safe (e.g. command line tool) @param private(bool): if True, also load sites from sites_path_private_dict """ - # TODO: self.host = host self.trusted = trusted self.sites_paths = { @@ -582,7 +582,7 @@ ## custom filters ## - @jinja2.contextfilter + @contextfilter def _front_url(self, ctx, relative_url): """Get front URL (URL seen by end-user) from a relative URL @@ -598,13 +598,13 @@ return os.path.join(site_root_dir, C.TEMPLATE_TPL_DIR, template_data.theme, relative_url) - @jinja2.contextfilter + @contextfilter def _next_gidx(self, ctx, value): """Use next current global index as suffix""" next_ = ctx["gidx"].next(value) return value if next_ == 0 else u"{}_{}".format(value, next_) - @jinja2.contextfilter + @contextfilter def _cur_gidx(self, ctx, value): """Use current current global index as suffix""" current = ctx["gidx"].current(value) @@ -653,7 +653,7 @@ continue return u" ".join(classes) or None - @jinja2.contextfilter + @contextfilter def _item_filter(self, ctx, item, filters): """return item's value, filtered if suitable