Esempio n. 1
0
def map_marker(ctx, req):
    """to allow for user-selectable markers, we have to look up a possible custom
    selection from the url params.
    """
    icon_map = req.registry.settings['icons']
    icon = None
    if IValue.providedBy(ctx):
        if 'v%s' % ctx.domainelement.number in req.params:
            icon = icon_map.get(req.params['v%s' % ctx.domainelement.number])
        else:
            icon = ctx.domainelement.jsondata['icon']
    elif IDomainElement.providedBy(ctx):
        if 'v%s' % ctx.number in req.params:
            icon = icon_map.get(req.params['v%s' % ctx.number])
        else:
            icon = ctx.jsondata['icon']
    elif ILanguage.providedBy(ctx):
        if ctx.genus.id in req.params:
            icon = icon_map.get(req.params[ctx.genus.id])
        else:
            icon = ctx.genus.icon
    elif isinstance(ctx, Genus):
        if ctx.id in req.params:
            icon = icon_map.get(req.params[ctx.id])
        else:
            icon = ctx.icon
    if icon:
        return req.static_url('clld:web/static/icons/' + icon + '.png')
Esempio n. 2
0
    def __call__(self, ctx, req):
        color, shape = None, 'c'
        if IValue.providedBy(ctx):
            if ctx.cognates:
                color = ctx.cognates[0].cognateset.color
            else:
                color = '#fff'

        if IValueSet.providedBy(ctx):
            v = ctx.values[0]
            if v.cognates:
                color = v.cognates[0].cognateset.color
            else:
                color = '#fff'
            if ctx.language.historical:
                shape = 'd'

        if ILanguage.providedBy(ctx):
            color = ctx.color
            if ctx.historical:
                shape = 'd'

        if color:
            if color.startswith('#'):
                color = color[1:]
            return svg.data_url(svg.icon(shape + color))

        return super(CoblMapMarker, self).__call__(ctx, req)
Esempio n. 3
0
def map_marker(ctx, req):
    """allow for user-selectable markers.

    we have to look up a possible custom selection from the url params.
    """
    icon = None

    if IValue.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.domainelement.number,
                              ctx.domainelement.jsondata['icon'])
    elif IDomainElement.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.number, ctx.jsondata['icon'])
    elif ILanguage.providedBy(ctx):
        icon = req.params.get(ctx.genus.id, ctx.genus.icon)
    elif isinstance(ctx, Genus):
        icon = req.params.get(ctx.id, ctx.icon)

    if icon:
        if "'" in icon:
            icon = icon.split("'")[0]
        if len(icon) > 4 and len(icon) != 7:
            icon = icon[:4]
        if len(icon) == 4:
            icon = icon[0] + 2 * icon[1] + 2 * icon[2] + 2 * icon[3]
        if icon.startswith('a'):
            return svg.data_url(svg.icon('c000000', opacity='0'))
        try:
            return svg.data_url(svg.icon(icon))
        except KeyError:
            return ''
    def __call__(self, ctx, req):
        if IDomainElement.providedBy(ctx):
            return url('c' + ctx.jsondata['color'])

        if IValue.providedBy(ctx):
            if ctx.domainelement:
                return url('c' + ctx.domainelement.jsondata['color'])
            if ctx.valueset.language.jsondata['icon']:
                return url(ctx.valueset.language.jsondata['icon'])

        if IValueSet.providedBy(ctx):
            if ctx.values[0].domainelement:
                return url('c' + ctx.values[0].domainelement.jsondata['color'])
            if ctx.language.jsondata['icon']:
                return url(ctx.language.jsondata['icon'])
            if ctx.language.family:
                return url(ctx.language.family.jsondata['icon'])
            return url(
                req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON))

        if ILanguage.providedBy(ctx):
            icon_ = ctx.jsondata['icon']
            return url(icon_)

        return super(LanguageByFamilyMapMarker, self).__call__(ctx, req)
Esempio n. 5
0
 def get_icon(self, ctx, req):
     if ILanguage.providedBy(ctx):
         if ctx.family:
             return ctx.family.jsondata['icon']
         return req.registry.settings.get('clld.isolates_icon',
                                          ISOLATES_ICON)
     return super(LanguageByFamilyMapMarker, self).get_icon(ctx, req)
Esempio n. 6
0
    def __call__(self, ctx, req):
        if IDomainElement.providedBy(ctx):
            return url('c' + ctx.jsondata['color'])

        if IValue.providedBy(ctx):
            if ctx.domainelement:
                return url('c' + ctx.domainelement.jsondata['color'])
            return url(ctx.valueset.language.family.jsondata['icon'])

        if IValueSet.providedBy(ctx):
            #
            # FIXME: To add genericity, draw a pie chart respecting all values!
            #
            if ctx.values[0].domainelement:
                return url('c' + ctx.values[0].domainelement.jsondata['color'])
            if ctx.language.family:
                return url(ctx.language.family.jsondata['icon'])
            return url(
                req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON))

        if ILanguage.providedBy(ctx):
            icon_ = super(LanguageByFamilyMapMarker, self).get_icon(ctx, req)
            if ctx.subgroup:
                icon_ = ctx.jsondata['shape'] + icon_[1:]
            return url(icon_)

        return super(LanguageByFamilyMapMarker, self).__call__(ctx, req)
Esempio n. 7
0
File: __init__.py Progetto: clld/ids
def link_attrs(req, obj, **kw):
    if ILanguage.providedBy(obj):
        # we are about to link to a language details page: redirect to contribution page!
        kw['href'] = req.route_url('contribution', id=obj.id, **kw.pop('url_kw', {}))
    if IValue.providedBy(obj):
        # we are about to link to a value details page: redirect to valueset page!
        kw['href'] = req.resource_url(obj.valueset, **kw.pop('url_kw', {}))
    return kw
Esempio n. 8
0
 def __call__(self, ctx, req):
     spec = None
     if IValueSet.providedBy(ctx):
         spec = 'c' + ctx.contribution.color
     elif IValue.providedBy(ctx):
         spec = 'c' + ctx.valueset.contribution.color
     elif ILanguage.providedBy(ctx):
         spec = 'ddd0000' if ctx.vocabulary else 'c4d6cee'
     return svg.data_url(svg.icon(spec)) if spec else \
         super(WoldMapMarker, self).__call__(ctx, req)
Esempio n. 9
0
    def __call__(self, ctx, req):
        if IValue.providedBy(ctx):
            return data_url(icon('c' +
                                 ctx.valueset.language.jsondata['color']))
        if IValueSet.providedBy(ctx):
            return data_url(icon('c' + ctx.language.jsondata['color']))
        elif ILanguage.providedBy(ctx):
            return data_url(icon('c' + ctx.jsondata['color']))

        return super(LanguageByCantonMapMarker,
                     self).__call__(ctx, req)  # pragma: no cover
Esempio n. 10
0
    def __call__(self, ctx, req):
        c = None
        if ILanguage.providedBy(ctx):
            c = ctx.jsondata.get('color')
        elif IValueSet.providedBy(ctx):
            c = ctx.language.jsondata.get('color')

        if c:
            return req.static_url('waab:static/%s.png' % c)

        return super(waabMapMarker, self).__call__(ctx, req)  # pragma: no cover
Esempio n. 11
0
 def __call__(self, ctx, req):
     asset_spec = None
     if IValueSet.providedBy(ctx):
         asset_spec = 'wold2:static/%s.png' % ctx.contribution.color
     elif IValue.providedBy(ctx):
         asset_spec = 'wold2:static/%s.png' % ctx.valueset.contribution.color
     elif ILanguage.providedBy(ctx):
         asset_spec = 'clld:web/static/icons/%s.png' % (
             'ddd0000' if ctx.vocabulary else 'c4d6cee',)
     return req.static_url(asset_spec) if asset_spec else \
         super(WoldMapMarker, self).__call__(ctx, req)
Esempio n. 12
0
 def __call__(self, ctx, req):
     asset_spec = None
     if IValueSet.providedBy(ctx):
         asset_spec = 'wold2:static/%s.png' % ctx.contribution.color
     elif IValue.providedBy(ctx):
         asset_spec = 'wold2:static/%s.png' % ctx.valueset.contribution.color
     elif ILanguage.providedBy(ctx):
         asset_spec = 'clld:web/static/icons/%s.png' % (
             'ddd0000' if ctx.vocabulary else 'c4d6cee', )
     return req.static_url(asset_spec) if asset_spec else \
         super(WoldMapMarker, self).__call__(ctx, req)
Esempio n. 13
0
File: __init__.py Progetto: clld/csd
 def __call__(self, ctx, req):
     lang = None
     if IValueSet.providedBy(ctx):
         lang = ctx.language
     elif IValue.providedBy(ctx):
         lang = ctx.valueset.language
     elif ILanguage.providedBy(ctx):
         lang = ctx
     if lang:
         return req.static_url('csd:static/icons/%s%s.png' % (
             't' if lang.proto else 'c', lang.color))
     return super(CsdMapMarker, self).__call__(ctx, req)  # pragma: no cover
Esempio n. 14
0
def link_attrs(req, obj, **kw):
    if ILanguage.providedBy(obj):
        # we are about to link to a language details page: redirect to contribution page!
        id_ = obj.language.id if obj.language else obj.id
        kw['href'] = req.route_url('contribution', id=id_, **kw.pop('url_kw', {}))

    if IValueSet.providedBy(obj) and obj.parameter_pk == 1:
        # we are about to link to a valueset of the "hidden" feature 0: redirect to
        # contribution page!
        kw['href'] = req.route_url(
            'contribution', id=obj.language.id, **kw.pop('url_kw', {}))

    return kw
Esempio n. 15
0
    def get_icon(self, ctx, req):
        lineage = None
        if ctx and isinstance(ctx, (tuple, list)):
            ctx = ctx[0]

        if ILanguage.providedBy(ctx):
            lineage = ctx.lineage

        if ctx in models.ICON_MAP:
            lineage = ctx

        if lineage:
            return 'c' + models.ICON_MAP.get(lineage, 'ffff00')
Esempio n. 16
0
def map_marker(ctx, req):
    """to allow for user-selectable markers, we have to look up a possible custom
    selection from the url params.
    """
    icon_map = {i.name: i for i in req.registry.getUtility(IIconList)}
    icon = None
    if IValue.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.domainelement.number,
                              ctx.domainelement.jsondata['icon'])
    elif IDomainElement.providedBy(ctx):
        icon = req.params.get('v' + str(ctx.number), ctx.jsondata['icon'])
    elif ILanguage.providedBy(ctx):
        icon = ctx.family.jsondata['icon']
    if icon and icon in icon_map:
        return icon_map[icon].url(req)
Esempio n. 17
0
def link_attrs(req, obj, **kw):
    if ILanguage.providedBy(obj):
        # we are about to link to a language details page: redirect to contribution page!
        id_ = obj.language.id if obj.language else obj.id
        kw['href'] = req.route_url('contribution',
                                   id=id_,
                                   **kw.pop('url_kw', {}))

    if IValueSet.providedBy(obj) and obj.parameter_pk == 1:
        # we are about to link to a valueset of the "hidden" feature 0: redirect to
        # contribution page!
        kw['href'] = req.route_url('contribution',
                                   id=obj.language.id,
                                   **kw.pop('url_kw', {}))

    return kw
Esempio n. 18
0
 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)
Esempio n. 19
0
def map_marker(ctx, req):
    """to allow for user-selectable markers, we have to look up a possible custom
    selection from the url params.
    """
    icon_map = {i.name: i for i in req.registry.getUtility(IIconList)}
    icon = None
    if IValue.providedBy(ctx):
        icon = req.params.get(
            'v%s' % ctx.domainelement.number,
            ctx.domainelement.jsondata['icon'])
    elif IDomainElement.providedBy(ctx):
        icon = req.params.get('v' + str(ctx.number), ctx.jsondata['icon'])
    elif ILanguage.providedBy(ctx):
        icon = ctx.family.jsondata['icon']
    if icon and icon in icon_map:
        return icon_map[icon].url(req)
Esempio n. 20
0
    def get_color(self, ctx, req):
        lineage = None
        if ctx and isinstance(ctx, (tuple, list)):
            ctx = ctx[0]

        if ILanguage.providedBy(ctx):
            lineage = ctx.lineage
        elif IValueSet.providedBy(ctx):
            lineage = ctx.language.lineage
        elif IValue.providedBy(ctx):
            lineage = ctx.valueset.language.lineage

        if isinstance(ctx, string_types):
            lineage = req.db.query(models.Lineage)\
                .filter(models.Lineage.name == ctx).one()

        return lineage.color if lineage else 'ff6600'
Esempio n. 21
0
    def get_color(self, ctx, req):
        lineage = None
        if ctx and isinstance(ctx, (tuple, list)):
            ctx = ctx[0]

        if ILanguage.providedBy(ctx):
            lineage = ctx.lineage
        elif IValueSet.providedBy(ctx):
            lineage = ctx.language.lineage
        elif IValue.providedBy(ctx):
            lineage = ctx.valueset.language.lineage

        if isinstance(ctx, str):
            lineage = req.db.query(models.Lineage)\
                .filter(models.Lineage.name == ctx).one()

        return lineage.color if lineage else 'ff6600'
Esempio n. 22
0
    def __call__(self, ctx, req):
        #if ILanguage.providedBy(ctx) or IValueSet.providedBy(ctx):
        #    return req.registry.getUtility(IIcon, 'c{0}'.format(ctx.jsondata['color'])).url(req)
        icon = None
        if ILanguage.providedBy(ctx):
            icon = ctx.languoid.jsondata['icon']
        elif IValue.providedBy(ctx):
            icon = ctx.jsondata['icon']
        elif IValueSet.providedBy(ctx):
            icon = ctx.jsondata['icon']
        if icon:
            try:
                return svg.data_url(svg.icon(icon))
            except:
                raise ValueError(icon)

        return super(GelatoMapMarker, self).__call__(ctx,
                                                     req)  # pragma: no cover
Esempio n. 23
0
    def __call__(self, ctx, req):
        
        mapping = {}
        count = -1
        shape = 'c'
        if IValueSet.providedBy(ctx):
            c = colors[ctx.language.family]
            if ctx.language.family in ['MIA', 'OIA'] or 'Old' in ctx.language.name:
                shape = 'd'
            return data_url(icon(shape + c))

        if ILanguage.providedBy(ctx):
            c = colors[ctx.family]
            if ctx.family in ['MIA', 'OIA'] or 'Old' in ctx.name:
                shape = 'd'
            return data_url(icon(shape + c))
    
        return super(LanguageByFamilyMapMarker, self).__call__(ctx, req)
Esempio n. 24
0
    def __call__(self, ctx, req):
        icon = None
        if IValueSet.providedBy(ctx):
            if req.matched_route.name == 'valueset' and not ctx.parameter.multivalued:
                return ''
            icon = ctx.jsondata['icon']

        if IValue.providedBy(ctx):
            icon = ctx.domainelement.jsondata['icon']

        if IDomainElement.providedBy(ctx):
            icon = ctx.jsondata['icon']

        if ILanguage.providedBy(ctx):
            icon = ctx.jsondata['icon']

        if icon:
            return req.static_url('plld_app:static/icons/%s' % icon)

        return super(ApicsMapMarker, self).__call__(ctx, req)
Esempio n. 25
0
    def __call__(self, ctx, req):
        icon = None
        if IValueSet.providedBy(ctx):
            if req.matched_route.name == 'valueset' and not ctx.parameter.multivalued:
                return ''
            icon = ctx.jsondata['icon']

        if IValue.providedBy(ctx):
            icon = ctx.domainelement.jsondata['icon']

        if IDomainElement.providedBy(ctx):
            icon = ctx.jsondata['icon']

        if ILanguage.providedBy(ctx):
            icon = ctx.jsondata['icon']

        if icon:
            return req.static_url('plld_app:static/icons/%s' % icon)

        return super(ApicsMapMarker, self).__call__(ctx, req)
Esempio n. 26
0
def map_marker(ctx, req):
    """to allow for user-selectable markers, we have to look up a possible custom
    selection from the url params.
    """
    icon_map = {i.name: i for i in req.registry.getUtility(IIconList)}
    icon = None

    if IValue.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.domainelement.number,
                              ctx.domainelement.jsondata['icon'])
    elif IDomainElement.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.number, ctx.jsondata['icon'])
    elif ILanguage.providedBy(ctx):
        icon = req.params.get(ctx.genus.id, ctx.genus.icon)
    elif isinstance(ctx, Genus):
        icon = req.params.get(ctx.id, ctx.icon)

    if icon:
        if len(icon) == 7:
            icon = ''.join([icon[i] for i in [0, 2, 4, 6]])
        if icon in icon_map:
            return icon_map[icon].url(req)
Esempio n. 27
0
def map_marker(ctx, req):
    """to allow for user-selectable markers, we have to look up a possible custom
    selection from the url params.
    """
    icon_map = {i.name: i for i in req.registry.getUtility(IIconList)}
    icon = None

    if IValue.providedBy(ctx):
        icon = req.params.get(
            'v%s' % ctx.domainelement.number,
            ctx.domainelement.jsondata['icon'])
    elif IDomainElement.providedBy(ctx):
        icon = req.params.get('v%s' % ctx.number, ctx.jsondata['icon'])
    elif ILanguage.providedBy(ctx):
        icon = req.params.get(ctx.genus.id, ctx.genus.icon)
    elif isinstance(ctx, Genus):
        icon = req.params.get(ctx.id, ctx.icon)

    if icon:
        if len(icon) == 7:
            icon = ''.join([icon[i] for i in [0, 2, 4, 6]])
        if icon in icon_map:
            return icon_map[icon].url(req)
Esempio n. 28
0
 def get_icon(self, ctx, req):
     if ILanguage.providedBy(ctx):
         if ctx.family:
             return ctx.family.jsondata['icon']
         return req.registry.settings.get('clld.isolates_icon', ISOLATES_ICON)
     return super(LanguageByFamilyMapMarker, self).get_icon(ctx, req)