# HG changeset patch # User Goffi # Date 1687444578 -7200 # Node ID 285c49d7aad3531007f46b17c3d1b48cd9f02443 # Parent 106945841fbca2a4951d939ccd2f99fd740f79e0 _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. diff -r 106945841fbc -r 285c49d7aad3 libervia/web/pages/_browser/template.py --- 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')