diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-04-17 22:26:30 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-04-17 22:26:30 +0200 |
commit | c79e93b4ba1c9fbd4cf1bf2d3b880fbf20405d7d (patch) | |
tree | 2f48fc4281cc393d4449cea69c97915dcc84bba5 /python/vyos/template.py | |
parent | ccfd6d24c41dc229f24317a90d1387c70ca2c674 (diff) | |
parent | ebece7a4cdb942ea1ff7582ceda0f8765c329c9b (diff) | |
download | vyos-1x-c79e93b4ba1c9fbd4cf1bf2d3b880fbf20405d7d.tar.gz vyos-1x-c79e93b4ba1c9fbd4cf1bf2d3b880fbf20405d7d.zip |
Merge branch 't2425-policy' of github.com:c-po/vyos-1x into current
* 't2425-policy' of github.com:c-po/vyos-1x:
policy: T2425: re-implement "policy" tree from vyatta-cfg-quagga in XML/Python
Diffstat (limited to 'python/vyos/template.py')
-rw-r--r-- | python/vyos/template.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/python/vyos/template.py b/python/vyos/template.py index 7810f5edd..3fbb33acb 100644 --- a/python/vyos/template.py +++ b/python/vyos/template.py @@ -346,3 +346,18 @@ def get_dhcp_router(interface): if 'option routers' in line: (_, _, address) = line.split() return address.rstrip(';') + +@register_filter('natural_sort') +def natural_sort(iterable): + import re + from jinja2.runtime import Undefined + + if isinstance(iterable, Undefined) or iterable is None: + return list() + + def convert(text): + return int(text) if text.isdigit() else text.lower() + def alphanum_key(key): + return [convert(c) for c in re.split('([0-9]+)', str(key))] + + return sorted(iterable, key=alphanum_key) |