Mercurial > libervia-web
changeset 1533:285c49d7aad3
_browser (template): add `media_type_main` and `media_type_sub` filters:
this is to follow main template module change, as string slicing is not done the same way
in jinja2 and nunjucks.
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 22 Jun 2023 16:36:18 +0200 (18 months ago) |
parents | 106945841fbc |
children | 49ad8dd210d0 |
files | libervia/web/pages/_browser/template.py |
diffstat | 1 files changed, 18 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/libervia/web/pages/_browser/template.py Thu Jun 22 16:36:01 2023 +0200 +++ b/libervia/web/pages/_browser/template.py Thu Jun 22 16:36:18 2023 +0200 @@ -130,6 +130,24 @@ env.addFilter("tojson", _tojson) +def _media_type_main(value: str|None) -> str|None: + """Return main type of a media type""" + if not value: + return None + return value.partition("/")[0] + +env.addFilter("media_type_main", _media_type_main) + + +def _media_type_sub(value: str|None) -> str|None: + """Return main type of a media type""" + if not value: + return None + return value.partition("/")[1] + +env.addFilter("media_type_sub", _media_type_sub) + + def _icon_use(name, cls=""): kwargs = cls.to_dict() cls = kwargs.get('cls')