Mercurial > libervia-backend
comparison libervia/backend/tools/common/template.py @ 4165:81faa85c9cfa
template: add a `bare_jid` filter
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 28 Nov 2023 17:41:49 +0100 |
parents | 810921c33a47 |
children | 0d7bb4df2343 |
comparison
equal
deleted
inserted
replaced
4164:15482dc0b5d1 | 4165:81faa85c9cfa |
---|---|
47 from libervia.backend.core.constants import Const as C | 47 from libervia.backend.core.constants import Const as C |
48 from libervia.backend.core.i18n import _ | 48 from libervia.backend.core.i18n import _ |
49 from libervia.backend.core.log import getLogger | 49 from libervia.backend.core.log import getLogger |
50 from libervia.backend.tools import config | 50 from libervia.backend.tools import config |
51 from libervia.backend.tools.common import date_utils | 51 from libervia.backend.tools.common import date_utils |
52 from libervia.frontends.tools import jid | |
52 | 53 |
53 log = getLogger(__name__) | 54 log = getLogger(__name__) |
54 | 55 |
55 try: | 56 try: |
56 import sat_templates | 57 import sat_templates |
467 | 468 |
468 # we want to have access to SàT constants in templates | 469 # we want to have access to SàT constants in templates |
469 self.env.globals["C"] = C | 470 self.env.globals["C"] = C |
470 | 471 |
471 # custom filters | 472 # custom filters |
473 self.env.filters["bare_jid"] = self._bare_jid | |
472 self.env.filters["next_gidx"] = self._next_gidx | 474 self.env.filters["next_gidx"] = self._next_gidx |
473 self.env.filters["cur_gidx"] = self._cur_gidx | 475 self.env.filters["cur_gidx"] = self._cur_gidx |
474 self.env.filters["date_fmt"] = self._date_fmt | 476 self.env.filters["date_fmt"] = self._date_fmt |
475 self.env.filters["timestamp_to_hour"] = self._timestamp_to_hour | 477 self.env.filters["timestamp_to_hour"] = self._timestamp_to_hour |
476 self.env.filters["delta_to_human"] = date_utils.delta2human | 478 self.env.filters["delta_to_human"] = date_utils.delta2human |
756 | 758 |
757 site_root_dir = self.sites_paths[template_data.site] | 759 site_root_dir = self.sites_paths[template_data.site] |
758 return os.path.join(site_root_dir, C.TEMPLATE_TPL_DIR, template_data.theme, | 760 return os.path.join(site_root_dir, C.TEMPLATE_TPL_DIR, template_data.theme, |
759 relative_url) | 761 relative_url) |
760 | 762 |
763 def _bare_jid(self, full_jid: str|jid.JID) -> str: | |
764 """Return the bare JID""" | |
765 return str(jid.JID(str(full_jid)).bare) | |
766 | |
761 @pass_context | 767 @pass_context |
762 def _next_gidx(self, ctx, value): | 768 def _next_gidx(self, ctx, value): |
763 """Use next current global index as suffix""" | 769 """Use next current global index as suffix""" |
764 next_ = ctx["gidx"].next(value) | 770 next_ = ctx["gidx"].next(value) |
765 return value if next_ == 0 else "{}_{}".format(value, next_) | 771 return value if next_ == 0 else "{}_{}".format(value, next_) |