datasource: organize items with optgroups in DataSourceSelectionWidget (#48283)

This commit is contained in:
Lauréline Guérin 2020-11-13 17:30:10 +01:00
parent d01b3c2ce9
commit 71a4174d63
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
1 changed files with 17 additions and 7 deletions

View File

@ -58,14 +58,24 @@ class DataSourceSelectionWidget(CompositeWidget):
if not value:
value = {}
options = []
if allow_named_sources:
options.extend([(x.slug, x.name, x.slug) for x in NamedDataSource.select()])
from wcs.carddef import CardDef
options.extend([(t[2], t[1], t[2]) for t in CardDef.get_carddefs_as_data_source()])
options.sort(key=lambda x: misc.simplify(x[1]))
options = [(None, _('None'), None)]
options.insert(0, (None, _('None'), None))
if allow_named_sources:
from wcs.carddef import CardDef
cards_options = [(t[2], t[1], t[2]) for t in CardDef.get_carddefs_as_data_source()]
cards_options.sort(key=lambda x: misc.simplify(x[1]))
if cards_options:
options.append(OptGroup(_('Cards')))
options.extend(cards_options)
nds_options = [(x.slug, x.name, x.slug) for x in NamedDataSource.select()]
nds_options.sort(key=lambda x: misc.simplify(x[1]))
if nds_options:
options.append(OptGroup(_('Manually Configured Data Sources')))
options.extend(nds_options)
if len(options) > 1:
options.append(OptGroup(_('Generic Data Sources')))
options.append(('json', _('JSON URL'), 'json'))
if allow_jsonp:
options.append(('jsonp', _('JSONP URL'), 'jsonp'))