def test_LanguageByFamilyMapMarker(self): from clld_glottologfamily_plugin.util import LanguageByFamilyMapMarker marker = LanguageByFamilyMapMarker() self.assertEqual(marker.get_icon(LanguageWithFamily.get('l1'), MagicMock()), 1) self.assertNotEqual(marker.get_icon(LanguageWithFamily.get('l2'), MagicMock()), 1) marker.get_icon(Family.first(), MagicMock())
def __call__(self, ctx, req): if IDomainElement.providedBy(ctx): return self.svg_icon(ctx) if IValue.providedBy(ctx): if ctx.domainelement_pk: return self.svg_icon(ctx.domainelement) return LanguageByFamilyMapMarker.__call__(self, ctx.valueset.language, req) if IValueSet.providedBy(ctx): if ctx.values[0].domainelement_pk: return self.svg_icon(ctx.values[0].domainelement) return LanguageByFamilyMapMarker.__call__(self, ctx.language, req) if ILanguage.providedBy(ctx): if ctx.family: return data_url(icon(ctx.family.jsondata['icon'])) return data_url(icon(req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON))) return LanguageByFamilyMapMarker.__call__(self, ctx, req)
def __call__(self, ctx, req): if IValue.providedBy(ctx): #print ctx.jsondata['family']#,ctx,[self],ctx.domainelement.jsondata['icon'] ##return ctx.domainelement.jsondata['icon'] return req.static_url('lsi:static/icons/' + ctx.jsondata['family'] + ctx.domainelement.jsondata['icon'] + '.png') ##return req.static_url('lsi:static/icons/c000000.png') if IValueSet.providedBy(ctx): #print ctx.domainelement ##return ctx.values[0].domainelement.jsondata['icon'] req.static_url('lsi:static/icons/' + ctx.values[0].domainelement.jsondata['icon'] + '.png') if IDomainElement.providedBy(ctx): ##return None print ctx.jsondata return req.static_url('lsi:static/icons/' + 'cr' + ''.join(ctx.jsondata['icon'][:]) + '.png') ##return ctx.jsondata['icon'] #print LanguageByFamilyMapMarker #print LanguageByFamilyMapMarker.get_icon(self, ctx, req) ##return LanguageByFamilyMapMarker.get_icon(self, ctx, req) return req.static_url( 'lsi:static/icons/' + LanguageByFamilyMapMarker.get_icon(self, ctx, req) + '.png')
def get_icon(self, ctx, req): if IValue.providedBy(ctx): return ctx.domainelement.jsondata['icon'] if IValueSet.providedBy(ctx): return ctx.values[0].domainelement.jsondata['icon'] if IDomainElement.providedBy(ctx): return ctx.jsondata['icon'] return LanguageByFamilyMapMarker.get_icon(self, ctx, req)
def main(global_config, **settings): """ This function returns a Pyramid WSGI application. """ # http://ldh.clld.org/category/iso639_3/aap-para-arara/ config = Configurator(settings=settings) config.include('clldmpg') config.include('clld_glottologfamily_plugin') config.registry.registerUtility(LanguageByFamilyMapMarker(), IMapMarker) # /feed/ -> /sources.atom """ /comments/feed/ /feed/ -> /sources.atom """ config.add_301('/about/', lambda req: req.route_url('dataset', id='ldh')) config.add_301('/about/objective/', lambda req: req.route_url('about', _anchor='objectives')) config.add_301('/repository/', lambda req: req.route_url('about', _anchor='repository')) config.add_301('/archive/', lambda req: req.route_url('sources')) config.add_301('/category/iso639_3/', lambda req: req.route_url('languages')) config.add_301('/category/allgemein/', lambda req: req.route_url('languages')) config.add_301('/contact/', lambda req: req.route_url('contact')) config.add_301('/for-authors/', lambda req: req.route_url('help')) config.add_301('/for-authors/{path}/', lambda req: req.route_url('help')) config.add_301('/feed/', lambda req: req.route_url('sources_alt', ext='atom')) config.add_301('/{year}/{month}/{day}/escidoc{id}/', lambda req: req.route_url( 'source', id='item_{0}'.format(req.matchdict['id'].split('-')[0]), _query=req.query_params), name='item') config.add_301( '/category/iso639_3/{id}/', lambda req: req.route_url('language', id=req.matchdict['id'].split('-')[0], _query=req.query_params), name='category') assert config.registry.unregisterUtility(provided=IDownload, name='dataset.cldf') config.register_download( adapters.BibTeX(models.Description, 'ldh', description="Descriptions as BibTeX")) return config.make_wsgi_app()
def __call__(self, ctx, req): if IValue.providedBy(ctx): icon = ctx.domainelement.jsondata['icon'] elif IValueSet.providedBy(ctx): icon = ctx.values[0].domainelement.jsondata['icon'] elif IDomainElement.providedBy(ctx): icon = ctx.jsondata['icon'] else: icon = LanguageByFamilyMapMarker.get_icon(self, ctx, req) icon = { 'cffffff': 'c0077bb', 'cff0000': 'ccc3311', 'c0000ff': 'c009988', 'cffff00': 'cee7733', }.get(icon, icon) return svg.data_url(svg.icon(icon, opacity=0.8))
def get_icon(self, ctx, req): if IValue.providedBy(ctx): ctx = ctx.valueset if IValueSet.providedBy(ctx): ctx = ctx.language return LanguageByFamilyMapMarker.get_icon(self, ctx, req)