def __init__(self, req, name, eid, collection=None, url=None, selected=None): MultiSelect.__init__(self, req, name, eid, url='x') self.data = [] for app, rm in req.registry.settings.get('clld.parameters', {}).items(): for param in rm['resources']: self.data.append({ 'id': '%s-%s' % (app, param['id']), 'text': '%s %s: %s' % (app, param['id'], param['name'])}) self._datadict = dict((d['id'], d) for d in self.data)
def __init__(self, ctx, req, name='cladefilter', eid='ms-cladefilter', **kw): if ctx.cladefilter and len(ctx.cladefilter[0]): kw['selected'] = ctx.cladefilter else: kw['selected'] = None MultiSelect.__init__(self, req, name, eid, **kw)
def test_MultiSelect(env): from clld.web.util.multiselect import MultiSelect ms = MultiSelect(env['request'], common.Language, 'x', url='/') ms.render() ms.render(selected=[common.Language.first()]) ms.format_result(common.Language(id='x'))
def browser(req): ms = MultiSelect(req, 'families', 'msfamily', collection=family_query(req), selected=_get_families(req)) focus = req.params.get('focus', 'ed') if focus == 'sdt': colors, shapes = SIMPLIFIED_DOCTYPES, ENDANGERMENTS else: shapes, colors = SIMPLIFIED_DOCTYPES, ENDANGERMENTS icon_map = {} for shape in [o.shape for o in shapes]: for color in [o.color for o in colors] + ['ffffff']: spec = shape + color icon_map[spec] = req.static_url('clld:web/static/icons/%s.png' % spec) return { 'families': ms, 'macroareas': DBSession.query(Macroarea).all(), 'map': DescStatsMap(language_query(req), req, icon_map, focus), 'icon_map': icon_map, 'focus': focus, 'doctypes': SIMPLIFIED_DOCTYPES, 'endangerments': ENDANGERMENTS }
def test_MultiSelect(self): from clld.web.util.multiselect import MultiSelect ms = MultiSelect(self.env['request'], common.Language, 'x', url='/') ms.render() ms.render(selected=[common.Language.first()]) ms.format_result(common.Language(id='x'))
def langdoccomplexquery(request): res = { 'dt': None, 'doctypes': DBSession.query(Doctype).order_by(Doctype.id), 'macroareas': DBSession.query(Macroarea).order_by(Macroarea.id), 'ms': {} } res['ms']['languoids'] = LanguoidsMultiSelect( request, Languoid, 'mslanguoids', url=request.route_url('glottolog.childnodes')) res['ms']['macroareas'] = MultiSelect(request, Macroarea, 'msmacroareas', collection=res['macroareas']) res['ms']['doctypes'] = MultiSelect(request, Doctype, 'msdoctypes', collection=res['doctypes']) res['params'], reqparams = get_params(request.params, **res) res['refs'] = getRefs(res['params']) if res['refs']: res['dt'] = Refs(request, Source, cq=1, **reqparams) fmt = request.params.get('format') if fmt: db = bibtex.Database([ref.bibtex() for ref in res['refs']]) for name, adapter in request.registry.getAdapters([db], IRepresentation): if name == fmt: return adapter.render_to_response(db, request) return HTTPNotAcceptable() return res
def browser(req): """ The main GlottoScope view, with selection controls, map and tally table. """ ms = MultiSelect(req, 'families', 'msfamily', collection=family_query(req), selected=_get_families(req)) focus = req.params.get('focus', 'ed') im = get_icon_map() if focus == 'sdt': colors, shapes = im['med'], im['aes'] else: shapes, colors = im['med'], im['aes'] icon_map = {} for shape in [o.shape for o in shapes.values()]: for color in [o.color for o in colors.values()] + ['ffffff']: spec = shape + color icon_map[spec] = req.static_url('clld:web/static/icons/%s.png' % spec) countries = OrderedDict() for c in req.params.getall('country'): countries[c] = DBSession.query(common.DomainElement).join(common.Parameter)\ .filter(common.Parameter.id == 'country')\ .filter(common.DomainElement.name == c)\ .one().description return { 'families': ms, 'macroareas': get_parameter('macroarea'), 'countries': countries, 'map': DescStatsMap(language_query(req), req, icon_map, focus, im), 'icon_map': icon_map, 'focus': focus, 'doctypes': [(de, Icon.from_spec(de.jsondata['icon'])) for de in get_parameter('med').domain], 'endangerments': [(de, Icon.from_spec(de.jsondata['icon'])) for de in get_parameter('aes').domain], }
def browser(req): ms = MultiSelect(req, 'families', 'msfamily', collection=family_query(req), selected=_get_families(req)) icon_map = {} for color in [sdt.color for sdt in SIMPLIFIED_DOCTYPES] + ['ffffff']: for shape in [ed.shape for ed in ENDANGERMENTS]: spec = shape + color icon_map[spec] = req.static_url('clld:web/static/icons/%s.png' % spec) return { 'families': ms, 'macroareas': DBSession.query(Macroarea).all(), 'map': DescStatsMap(language_query(req), req, icon_map), 'icon_map': icon_map, 'doctypes': SIMPLIFIED_DOCTYPES, 'endangerments': ENDANGERMENTS }
def __init__(self, ctx, req, name, eid, **kw): if getattr(ctx, name) and len(getattr(ctx, name)[0]): kw['selected'] = getattr(ctx, name) else: kw['selected'] = None MultiSelect.__init__(self, req, name, eid, **kw)
def __init__(self, ctx, req, name='languages', eid='ms-languages', **kw): kw['selected'] = ctx.languages MultiSelect.__init__(self, req, name, eid, **kw)