Commit e4082599 authored by Ad Schellevis's avatar Ad Schellevis

configd, templates, add sortDictList to helpers. closes...

configd, templates, add sortDictList to helpers. closes https://github.com/opnsense/core/issues/1641

example usage:
{%  for item in helpers.sortDictList(OPNsense.ConfigObject, 'description') %}
    {{item.description}}
{%  endfor %}
parent 84a99758
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
""" """
import netaddr import netaddr
import operator
# noinspection PyPep8Naming # noinspection PyPep8Naming
...@@ -116,3 +117,11 @@ class Helpers(object): ...@@ -116,3 +117,11 @@ class Helpers(object):
:return: IPNetwork :return: IPNetwork
""" """
return netaddr.IPNetwork(network) return netaddr.IPNetwork(network)
@staticmethod
def sortDictList(lst, *operators):
if type(lst) == list:
lst.sort(key=operator.itemgetter(*operators))
elif type(lst) == dict:
return [lst]
return lst
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment