Mercurial > libervia-backend
changeset 3274:430204a3cc10
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.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 18 May 2020 23:41:36 +0200 |
parents | 4230aaeab9a7 |
children | 55eeb0dfd313 |
files | sat/tools/common/template.py |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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 @@ ' <use href="#{name}"/>' '</svg>\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 = []