Пример #1
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'])
            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)
Пример #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)
Пример #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 ''
Пример #4
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)
Пример #5
0
def link_attrs(req, obj, **kw):
    if IValue.providedBy(obj):
        # redirect value details to valueset details:
        kw['href'] = req.route_url('valueset',
                                   id=obj.valueset.id,
                                   **kw.pop('url_kw', {}))
    return kw
Пример #6
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')
Пример #7
0
 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')
Пример #8
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!
        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
Пример #9
0
 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)
Пример #10
0
 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)
Пример #11
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)
Пример #12
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
Пример #13
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)
Пример #14
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)
Пример #15
0
 def get_icon(self, ctx, req):
     """to 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 = ctx.domainelement.jsondata['icon']
     elif IDomainElement.providedBy(ctx):
         icon = ctx.jsondata['icon']
     if icon:
         return icon
     return super(NtsMapMarker, self).get_icon(ctx, req)
Пример #16
0
 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
Пример #17
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)
Пример #18
0
class LanguageByFamilyMapMarker(util.LanguageByFamilyMapMarker):
    def __call__(self, ctx, req):
    {% if cookiecutter.cldf_module.lower() == 'wordlist' %}
        if IValueSet.providedBy(ctx):
            if ctx.language.family:
                return data_url(icon(ctx.language.family.jsondata['icon']))
            return data_url(icon(req.registry.settings.get('clld.isolates_icon', util.ISOLATES_ICON)))
    {% elif cookiecutter.cldf_module.lower() == 'structuredataset' %}
        if IValueSet.providedBy(ctx):
            c = collections.Counter([v.domainelement.jsondata['color'] for v in ctx.values])
            return data_url(pie(*list(zip(*[(v, k) for k, v in c.most_common()])), **dict(stroke_circle=True)))
        if IDomainElement.providedBy(ctx):
            return data_url(icon(ctx.jsondata['color'].replace('#', 'c')))
        if IValue.providedBy(ctx):
            return data_url(icon(ctx.domainelement.jsondata['color'].replace('#', 'c')))
Пример #19
0
 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))
Пример #20
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)
Пример #21
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)
Пример #22
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 icon:
            return req.static_url('apics:static/icons/%s' % icon)

        return super(ApicsMapMarker, self).__call__(ctx, req)
Пример #23
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 icon:
            return req.static_url('apics:static/icons/%s' % icon)

        return super(ApicsMapMarker, self).__call__(ctx, req)
Пример #24
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'
Пример #25
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'
Пример #26
0
    def __call__(self, ctx, req):
        if IValueSet.providedBy(ctx):
            if req.matched_route.name == 'valueset' and not ctx.parameter.multivalued:
                return self.pie((100, ctx.values[0].domainelement.jsondata['color']))
            return self.pie_from_filename(ctx.jsondata['icon'])

        if IValue.providedBy(ctx):
            freq = ctx.frequency or 100
            slices = [(freq, ctx.domainelement.jsondata['color'])]
            if freq < 100:
                slices.append((100 - freq, 'ffffff'))
            return self.pie(*slices)

        if IDomainElement.providedBy(ctx):
            return self.pie((100, ctx.jsondata['color']))

        return super(ApicsMapMarker, self).__call__(ctx, req)
Пример #27
0
    def __call__(self, ctx, req):
        if IValueSet.providedBy(ctx):
            if req.matched_route.name == 'valueset' and not ctx.parameter.multivalued:
                return self.pie(
                    (100, ctx.values[0].domainelement.jsondata['color']))
            return self.pie_from_filename(ctx.jsondata['icon'])

        if IValue.providedBy(ctx):
            freq = ctx.frequency or 100
            slices = [(freq, ctx.domainelement.jsondata['color'])]
            if freq < 100:
                slices.append((100 - freq, 'ffffff'))
            return self.pie(*slices)

        if IDomainElement.providedBy(ctx):
            return self.pie((100, ctx.jsondata['color']))

        return super(ApicsMapMarker, self).__call__(ctx, req)
Пример #28
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
Пример #29
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)
Пример #30
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)
Пример #31
0
def frequency_marker(ctx, req):
    if IValue.providedBy(ctx):
        return req.static_url('apics:static/icons/%s' %
                              ctx.jsondata['frequency_icon'])
Пример #32
0
 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)
Пример #33
0
 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)
Пример #34
0
def frequency_marker(ctx, req):
    if IValue.providedBy(ctx):
        return req.static_url(
            'apics:static/icons/%s' % ctx.jsondata['frequency_icon'])