Mercurial > kallithea
changeset 7837:4f8428f467c8
helpers: handle webhelpers2 select with option groups
b077cf7e7f90 missed that we have those - for example for PR creation.
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 18 Aug 2019 20:15:45 +0200 |
parents | 3fd3ce1dc646 |
children | d1d04b52e3f5 |
files | kallithea/lib/helpers.py |
diffstat | 1 files changed, 14 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/lib/helpers.py Sun Aug 18 18:08:10 2019 +0200 +++ b/kallithea/lib/helpers.py Sun Aug 18 20:15:45 2019 +0200 @@ -163,7 +163,7 @@ """Convenient wrapper of webhelpers2 to let it accept options as a tuple list""" if isinstance(options, list): option_list = options - # Handle old style value,label lists + # Handle old value,label lists ... where value also can be value,label lists options = Options() for x in option_list: if isinstance(x, tuple) and len(x) == 2: @@ -173,7 +173,19 @@ else: log.error('invalid select option %r', x) raise - options.add_option(label, value) + if isinstance(value, list): + og = options.add_optgroup(label) + for x in value: + if isinstance(x, tuple) and len(x) == 2: + group_value, group_label = x + elif isinstance(x, basestring): + group_value = group_label = x + else: + log.error('invalid select option %r', x) + raise + og.add_option(group_label, group_value) + else: + options.add_option(label, value) return webhelpers2_select(name, selected_values, options, id=id, **attrs)