Mercurial > kallithea
changeset 7836:3fd3ce1dc646
helpers: refactor select to build Options without temporary list
The API seems slightly more suited for that.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 18 Aug 2019 18:08:10 +0200 |
parents | 41f780117963 |
children | 4f8428f467c8 |
files | kallithea/lib/helpers.py |
diffstat | 1 files changed, 5 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Sun Aug 18 15:52:33 2019 +0200 +++ b/kallithea/lib/helpers.py Sun Aug 18 18:08:10 2019 +0200 @@ -162,8 +162,10 @@ def select(name, selected_values, options, id=NotGiven, **attrs): """Convenient wrapper of webhelpers2 to let it accept options as a tuple list""" if isinstance(options, list): - l = [] - for x in options: + option_list = options + # Handle old style value,label lists + options = Options() + for x in option_list: if isinstance(x, tuple) and len(x) == 2: value, label = x elif isinstance(x, basestring): @@ -171,8 +173,7 @@ else: log.error('invalid select option %r', x) raise - l.append(Option(label, value)) - options = Options(l) + options.add_option(label, value) return webhelpers2_select(name, selected_values, options, id=id, **attrs)