Changeset - 3fd3ce1dc646
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-08-18 18:08:10
mads@kiilerich.com
helpers: refactor select to build Options without temporary list

The API seems slightly more suited for that.
1 file changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -162,8 +162,10 @@ def reset(name, value, id=NotGiven, **at
 
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 @@ def select(name, selected_values, option
 
            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)
 

	
 

	
0 comments (0 inline, 0 general)