Changeset - 41f780117963
[Not reviewed]
default
0 1 0
Mads Kiilerich - 6 years ago 2019-08-18 15:52:33
mads@kiilerich.com
Grafted from: 26bf5e23891b
helpers: fix bad handling of select values with length 2 - 'hg' showed up as 'g' in repo types list

Strings with length 2 are not tuples ...
1 file changed with 6 insertions and 7 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/helpers.py
Show inline comments
 
@@ -161,20 +161,19 @@ 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:
 
            try:
 
            if isinstance(x, tuple) and len(x) == 2:
 
                value, label = x
 
            except ValueError: # too many values to unpack
 
                if isinstance(x, basestring):
 
                    value = label = x
 
                else:
 
                    log.error('invalid select option %r', x)
 
                    raise
 
            elif isinstance(x, basestring):
 
                value = label = x
 
            else:
 
                log.error('invalid select option %r', x)
 
                raise
 
            l.append(Option(label, value))
 
        options = Options(l)
 
    return webhelpers2_select(name, selected_values, options, id=id, **attrs)
 

	
 

	
 
safeid = _make_safe_id_component
0 comments (0 inline, 0 general)