From 205bd5cdb4a0e6391f53213f41308f6990b74482 Mon Sep 17 00:00:00 2001 From: Goffi Date: Mon, 18 May 2020 23:41:36 +0200 Subject: [PATCH] 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. --- sat/tools/common/template.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/sat/tools/common/template.py b/sat/tools/common/template.py index e985496d..3bd07003 100644 --- a/sat/tools/common/template.py +++ b/sat/tools/common/template.py @@ -911,6 +911,21 @@ class Renderer(object): ' ' '\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 @@ class Renderer(object): kwargs["icon_defs"] = self._icon_defs kwargs["icon"] = self._icon_use + kwargs["icon_from_client"] = self._icon_from_client if css_inline: css_contents = []