# HG changeset patch # User Goffi # Date 1589838096 -7200 # Node ID 430204a3cc10f8a362e37429d9bd11d3d59ea763 # Parent 4230aaeab9a7e5cb9305be5355e132c2912b2f4d tools (common/template): new `icon_from_client` method: this method is available from template, and returns the name of the icon to use according to disco client data. diff -r 4230aaeab9a7 -r 430204a3cc10 sat/tools/common/template.py --- a/sat/tools/common/template.py Mon May 18 23:39:41 2020 +0200 +++ b/sat/tools/common/template.py Mon May 18 23:41:36 2020 +0200 @@ -911,6 +911,21 @@ ' ' '\n'.format(name=name, cls=(" " + cls) if cls else "")) + def _icon_from_client(self, client): + """Get icon name to represent a disco client""" + if client is None: + return 'desktop' + elif 'pc' in client: + return 'desktop' + elif 'phone' in client: + return 'mobile' + elif 'web' in client: + return 'globe' + elif 'console' in client: + return 'terminal' + else: + return 'desktop' + def render(self, template, site=None, theme=None, locale=C.DEFAULT_LOCALE, media_path="", css_files=None, css_inline=False, **kwargs): """Render a template @@ -963,6 +978,7 @@ kwargs["icon_defs"] = self._icon_defs kwargs["icon"] = self._icon_use + kwargs["icon_from_client"] = self._icon_from_client if css_inline: css_contents = []