# HG changeset patch # User Mads Kiilerich # Date 1566144490 -7200 # Node ID 3fd3ce1dc646afa476fb5270e692dda83da9e50a # Parent 41f780117963671ccf2dbc77f0ee1aa19370ef86 helpers: refactor select to build Options without temporary list The API seems slightly more suited for that. diff -r 41f780117963 -r 3fd3ce1dc646 kallithea/lib/helpers.py --- 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)