55 |
55 |
|
56 |
56 |
class DataSourceSelectionWidget(CompositeWidget):
|
57 |
57 |
def __init__(
|
58 |
|
self, name, value=None, allow_jsonp=True, allow_geojson=False, allow_named_sources=True, **kwargs
|
|
58 |
self,
|
|
59 |
name,
|
|
60 |
value=None,
|
|
61 |
allow_jsonp=True,
|
|
62 |
allow_geojson=False,
|
|
63 |
allow_named_sources=True,
|
|
64 |
restrict_to_card_sources=False,
|
|
65 |
**kwargs,
|
59 |
66 |
):
|
60 |
67 |
CompositeWidget.__init__(self, name, value, **kwargs)
|
61 |
68 |
|
62 |
69 |
if not value:
|
63 |
70 |
value = {}
|
64 |
71 |
|
65 |
|
options = [(None, _('None'), None)]
|
66 |
|
|
67 |
|
if allow_named_sources:
|
|
72 |
def _add_card_options(options):
|
68 |
73 |
from wcs.carddef import CardDef
|
69 |
74 |
|
70 |
75 |
cards_options = [
|
... | ... | |
78 |
83 |
options.append(OptGroup(_('Cards')))
|
79 |
84 |
options.extend(cards_options)
|
80 |
85 |
|
|
86 |
def _add_nameddatasource_options(options):
|
81 |
87 |
admin_accessible = NamedDataSource.is_admin_accessible()
|
82 |
88 |
nds_options = []
|
83 |
89 |
nds_agenda_options = []
|
... | ... | |
136 |
142 |
options.append(OptGroup(name or _('Without category')))
|
137 |
143 |
options.extend(nds_by_category_names[name])
|
138 |
144 |
|
139 |
|
if len(options) > 1:
|
140 |
|
options.append(OptGroup(_('Generic Data Sources')))
|
141 |
|
options.append(('json', _('JSON URL'), 'json', {'data-maybe-datetimes': 'true'}))
|
142 |
|
if allow_jsonp and (
|
143 |
|
value.get('type') == 'jsonp' or not get_publisher().has_site_option('disable-jsonp-sources')
|
144 |
|
):
|
145 |
|
options.append(('jsonp', _('JSONP URL'), 'jsonp'))
|
146 |
|
if allow_geojson:
|
147 |
|
options.append(('geojson', _('GeoJSON URL'), 'geojson'))
|
148 |
|
if not get_publisher().has_site_option('disable-python-expressions'):
|
149 |
|
options.append(('formula', _('Python Expression'), 'python'))
|
|
145 |
def _add_generic_options(options):
|
|
146 |
if len(options) > 1:
|
|
147 |
options.append(OptGroup(_('Generic Data Sources')))
|
|
148 |
options.append(('json', _('JSON URL'), 'json', {'data-maybe-datetimes': 'true'}))
|
|
149 |
if allow_jsonp and (
|
|
150 |
value.get('type') == 'jsonp' or not get_publisher().has_site_option('disable-jsonp-sources')
|
|
151 |
):
|
|
152 |
options.append(('jsonp', _('JSONP URL'), 'jsonp'))
|
|
153 |
if allow_geojson:
|
|
154 |
options.append(('geojson', _('GeoJSON URL'), 'geojson'))
|
|
155 |
if not get_publisher().has_site_option('disable-python-expressions'):
|
|
156 |
options.append(('formula', _('Python Expression'), 'python'))
|
|
157 |
|
|
158 |
options = [(None, _('None'), None)]
|
|
159 |
if allow_named_sources:
|
|
160 |
_add_card_options(options)
|
|
161 |
if not restrict_to_card_sources:
|
|
162 |
_add_nameddatasource_options(options)
|
|
163 |
if not restrict_to_card_sources:
|
|
164 |
_add_generic_options(options)
|
150 |
165 |
|
151 |
166 |
self.add(
|
152 |
167 |
SingleSelectWidget,
|