# HG changeset patch # User Goffi # Date 1744388357 -7200 # Node ID 4a8bb49b9d0fc138c21ce84b9413aefbf9989686 # Parent e22a5d80be02558cd370564e678df3ccf87d3959 template: Add `initials` filter. diff -r e22a5d80be02 -r 4a8bb49b9d0f libervia/backend/tools/common/template.py --- a/libervia/backend/tools/common/template.py Fri Apr 11 18:18:50 2025 +0200 +++ b/libervia/backend/tools/common/template.py Fri Apr 11 18:19:17 2025 +0200 @@ -497,6 +497,7 @@ self.env.globals["C"] = C # custom filters + self.env.filters["initials"] = self._initials self.env.filters["bare_jid"] = self._bare_jid self.env.filters["next_gidx"] = self._next_gidx self.env.filters["cur_gidx"] = self._cur_gidx @@ -799,6 +800,17 @@ """Return the bare JID""" return str(jid.JID(str(full_jid)).bare) + def _initials(self, name: str) -> str: + """Return the uppercased initials of a name.""" + name_parts = name.strip().split() + if not name_parts: + initials = "??" + elif len(name_parts) == 1: + initials = name_parts[0][:2] + else: + initials = name_parts[0][0] + name_parts[1][0] + return initials.upper() + @pass_context def _next_gidx(self, ctx, value): """Use next current global index as suffix"""