示例#1
0
文件: base.py 项目: FieldDB/clld
 def toolbar(self):
     """
     """
     return HTML.div(
         button(
             icon('info-sign', inverted=True),
             class_='btn-info %s-cdOpener' % self.eid),
         HTML.a(
             icon('download-alt'),
             HTML.span(class_="caret"),
             **{
                 'class_': "btn dropdown-toggle",
                 'data-toggle': "dropdown",
                 'href': "#",
                 'id': "dt-dl-opener",
             }
         ),
         HTML.ul(
             #HTML.li(HTML.a('csv', href="#")),
             *[HTML.li(HTML.a(
                 fmt,
                 href="#",
                 onclick="document.location.href = CLLD.DataTable.current_url"
                 "('%s', '%s'); return false;" % (self.eid, fmt),
                 id='dt-dl-%s' % fmt))
               for fmt in
               [a.extension for n, a in
                self.req.registry.getAdapters([self.model()], IIndex)]
               if fmt != 'html'],
             **dict(class_="dropdown-menu")),
         class_='btn-group right')
示例#2
0
文件: helpers.py 项目: FieldDB/clld
def alt_representations(req, rsc, doc_position='right', exclude=None):
    exclude = exclude or []
    exclude.extend(['html', 'snippet.html'])
    adapters = [a for n, a in req.registry.getAdapters([rsc], interfaces.IRepresentation)
                if a.extension not in set(exclude)]
    doc = []
    for adapter in adapters:
        if adapter.__doc__:
            doc.append(HTML.dt(adapter.name or adapter.extension))
            doc.append(HTML.dd(adapter.__doc__))
    doc = HTML.div(
        HTML.p(
            """You may download alternative representations of the data on
"%s" by clicking the button """ % rsc.name,
            icon('download-alt')),
        HTML.dl(*doc))
    return HTML.div(HTML.div(
        button(
            icon('info-sign', inverted=True),
            **{'class': ['btn-info'],
               'id': 'rsc-dl',
               'data-content': unicode(doc)}),
        HTML.a(
            icon('download-alt'),
            HTML.span(class_="caret"),
            **{
                'class_': "btn dropdown-toggle",
                'data-toggle': "dropdown",
                'href': "#",
                'id': "dt-dl-opener",
            }
        ),
        HTML.ul(
            *[HTML.li(HTML.a(
                a.name or a.extension,
                href="#",
                onclick="document.location.href = '%s'; return false;"
                        % req.resource_url(rsc, ext=a.extension),
                id='dt-dl-%s' % a.extension))
              for a in adapters],
            **dict(class_="dropdown-menu")),
        class_='btn-group'),
        HTML.script(literal("""\
    $(document).ready(function() {
        $('#rsc-dl').clickover({
            html: true,
            title: 'Alternative representations',
            placement: '%s',
            trigger: 'click'
        });
    });""" % doc_position)))
示例#3
0
def linked_image(obj, check=True):
    if check and maintype(obj) != 'image':
        raise ValueError('type mismatch: {0} and image'.format(maintype(obj)))
    return HTML.a(
        HTML.img(src=bitstream_url(obj, 'web'), class_='image'),
        href=bitstream_url(obj),
        title="View image ({0})".format(format_size(obj.jsondata.get('size', 0))))
示例#4
0
def change_request_link(cr_id, iso_code=None, label=None):
    url = 'http://www.sil.org/iso639-3/chg_detail.asp?id={0}'
    args = [cr_id]
    if iso_code:
        url += '&lang={1}'
        args.append(iso_code)
    return HTML.a(label or cr_id, href=url.format(*args))
示例#5
0
    def get_legends(self):
        if len(self.layers) > 1:
            items = []
            total = 0
            repr_attrs = dict(class_='pull-right stay-open', style="padding-right: 10px;")

            for layer in self.layers:
                representation = ''
                if hasattr(layer, 'representation'):
                    total += layer.representation
                    representation = HTML.span(str(layer.representation), **repr_attrs)
                items.append([
                    HTML.label(
                        HTML.input(
                            class_="stay-open",
                            type="checkbox",
                            checked="checked",
                            onclick=helpers.JS_CLLD.mapToggleLayer(
                                self.eid, layer.id, helpers.JS("this"))),
                        getattr(layer, 'marker', ''),
                        layer.name,
                        class_="checkbox inline stay-open",
                        style="margin-left: 5px; margin-right: 5px;",
                    ),
                    representation,
                ])
            if total:
                items.append(HTML.span(HTML.b(str(total)), **repr_attrs))
            yield Legend(
                self,
                'layers',
                items,
                label='Legend',
                stay_open=True,
                item_attrs=dict(style='clear: right'))
        items = []
        for size in [15, 20, 30, 40]:
            attrs = dict(name="iconsize", value=str(size), type="radio")
            if size == self.options.get('icon_size', 30):
                attrs['checked'] = 'checked'
            items.append(HTML.label(
                HTML.input(onclick=helpers.JS_CLLD.mapResizeIcons(self.eid), **attrs),
                HTML.img(
                    height=str(size),
                    width=str(size),
                    src=self.req.registry.getUtility(IIcon, 'cff6600').url(self.req)),
                class_="radio",
                style="margin-left: 5px; margin-right: 5px;"))
        yield Legend(
            self,
            'iconsize',
            items,
            label='Icon size')

        item = lambda layer: HTML.a(
            layer.name,
            onclick='return %s;' % helpers.JS_CLLD.mapShowGeojson(self.eid, layer.id),
            href=layer.data if isinstance(layer.data, string_types) else '#')
        yield Legend(
            self, 'geojson', map(item, self.layers), label='GeoJSON', pull_right=True)
示例#6
0
def linked_image(obj, check=True):
    if check and maintype(obj) != 'image':
        raise ValueError('type mismatch: {0} and image'.format(maintype(obj)))
    return HTML.a(
        HTML.img(src=bitstream_url(obj, 'web'), class_='image'),
        href=bitstream_url(obj),
        title="View image ({0})".format(format_size(obj.jsondata.get('size', 0))))
示例#7
0
文件: util.py 项目: MacyL/lexibank
def concepticon_link(request, concept):
    return HTML.a(HTML.img(
        src=request.static_url('lexibank:static/concepticon_logo.png'),
        height=20,
        width=30),
                  title='corresponding concept set at Concepticon',
                  href=concept.concepticon_url)
示例#8
0
文件: helpers.py 项目: clld/clld
def cc_link(req, license_url, button='regular'):
    if license_url == 'https://en.wikipedia.org/wiki/Public_domain':
        license_url = 'https://creativecommons.org/publicdomain/zero/1.0/'
    license_url = URL(license_url)
    if license_url.host() != 'creativecommons.org':
        return

    comps = license_url.path().split('/')
    if len(comps) < 3:
        return  # pragma: no cover

    known = {
        'zero': 'Public Domain',
        'by': 'Creative Commons Attribution License',
        'by-nc': 'Creative Commons Attribution-NonCommercial License',
        'by-nc-nd': 'Creative Commons Attribution-NonCommercial-NoDerivatives License',
        'by-nc-sa': 'Creative Commons Attribution-NonCommercial-ShareAlike License',
        'by-nd': 'Creative Commons Attribution-NoDerivatives License',
        'by-sa': 'Creative Commons Attribution-ShareAlike License'}
    if comps[2] not in known:
        return

    icon = 'cc-' + comps[2] + ('-small' if button == 'small' else '') + '.png'
    img_attrs = dict(
        alt=known[comps[2]],
        src=req.static_url('clld:web/static/images/' + icon))
    height, width = (15, 80) if button == 'small' else (30, 86)
    img_attrs.update(height=height, width=width)
    return HTML.a(HTML.img(**img_attrs), href=license_url, rel='license')
示例#9
0
def format_external_link_in_label(url, label=None):
    label = label or URL(url).domain()
    return HTML.span(HTML.a(HTML.i('', class_="icon-share icon-white"),
                            label,
                            href=url,
                            style="color: white"),
                     class_="label label-info")
示例#10
0
def link(req, obj, **kw):
    get_link_attrs = req.registry.queryUtility(interfaces.ILinkAttrs)
    if get_link_attrs:
        kw = get_link_attrs(req, obj, **kw)

    if 'class_' in kw:
        kw['class'] = kw['class_']
        del kw['class_']

    rsc = None
    rsc_name = kw.pop('rsc', None)
    for _rsc in RESOURCES:
        if _rsc.interface.providedBy(obj) or _rsc.name == rsc_name:
            rsc = _rsc
            break
    assert rsc
    href = kw.pop('href', req.resource_url(obj,
                                           rsc=rsc,
                                           **kw.pop('url_kw', {})))
    kw['class'] = ' '.join(
        filter(None,
               kw.get('class', '').split() + [rsc.interface.__name__[1:]]))
    label = kw.pop('label', unicode(obj))
    kw.setdefault('title', label)
    return HTML.a(label, href=href, **kw)
示例#11
0
def cc_link(req, license_url, button='regular'):
    if license_url == 'https://en.wikipedia.org/wiki/Public_domain':
        license_url = 'https://creativecommons.org/publicdomain/zero/1.0/'  # pragma: no cover
    license_url = URL(license_url)
    if license_url.host() != 'creativecommons.org':
        return

    comps = license_url.path().split('/')
    if len(comps) < 3:
        return  # pragma: no cover

    known = {
        'zero': 'Public Domain',
        'by': 'Creative Commons Attribution License',
        'by-nc': 'Creative Commons Attribution-NonCommercial License',
        'by-nc-nd': 'Creative Commons Attribution-NonCommercial-NoDerivatives License',
        'by-nc-sa': 'Creative Commons Attribution-NonCommercial-ShareAlike License',
        'by-nd': 'Creative Commons Attribution-NoDerivatives License',
        'by-sa': 'Creative Commons Attribution-ShareAlike License'}
    if comps[2] not in known:
        return

    icon = 'cc-' + comps[2] + ('-small' if button == 'small' else '') + '.png'
    img_attrs = dict(
        alt=known[comps[2]],
        src=req.static_url('clld:web/static/images/' + icon))
    height, width = (15, 80) if button == 'small' else (30, 86)
    img_attrs.update(height=height, width=width)
    return HTML.a(HTML.img(**img_attrs), href=license_url, rel='license')
示例#12
0
def cc_link(req, license_url, button="regular"):
    if license_url == "http://en.wikipedia.org/wiki/Public_domain":
        license_url = "http://creativecommons.org/publicdomain/zero/1.0/"
    license_url = URL(license_url)
    if license_url.host() != "creativecommons.org":
        return

    comps = license_url.path().split("/")
    if len(comps) < 3:
        return  # pragma: no cover

    known = {
        "zero": "Public Domain",
        "by": "Creative Commons Attribution License",
        "by-nc": "Creative Commons Attribution-NonCommercial License",
        "by-nc-nd": "Creative Commons Attribution-NonCommercial-NoDerivatives License",
        "by-nc-sa": "Creative Commons Attribution-NonCommercial-ShareAlike License",
        "by-nd": "Creative Commons Attribution-NoDerivatives License",
        "by-sa": "Creative Commons Attribution-ShareAlike License",
    }
    if comps[2] not in known:
        return

    icon = "cc-" + comps[2] + ("-small" if button == "small" else "") + ".png"
    img_attrs = dict(alt=known[comps[2]], src=req.static_url("clld:web/static/images/" + icon))
    height, width = (15, 80) if button == "small" else (30, 86)
    img_attrs.update(height=height, width=width)
    return HTML.a(HTML.img(**img_attrs), href=license_url, rel="license")
示例#13
0
def link(req, id=None, obj_type='ConceptSet', label=None):
    akw = dict(
        title='Concepticon' if id is None else 'View {0} at Concepticon'.format(obj_type),
        href=url(id=id, obj_type=obj_type))
    if label:
        return external_link(None, label=label, **akw)
    return HTML.a(logo(req), **akw)
示例#14
0
文件: __init__.py 项目: FieldDB/clld
    def get_legends(self):
        if len(self.layers) > 1:
            items = []
            total = 0
            repr_attrs = dict(class_='pull-right stay-open', style="padding-right: 10px;")

            for layer in self.layers:
                representation = ''
                if hasattr(layer, 'representation'):
                    total += layer.representation
                    representation = HTML.span(str(layer.representation), **repr_attrs)
                items.append([
                    HTML.label(
                        HTML.input(
                            class_="stay-open",
                            type="checkbox",
                            checked="checked",
                            onclick=helpers.JS_CLLD.mapToggleLayer(
                                self.eid, layer.id, helpers.JS("this"))),
                        getattr(layer, 'marker', ''),
                        layer.name,
                        class_="checkbox inline stay-open",
                        style="margin-left: 5px; margin-right: 5px;",
                    ),
                    representation,
                ])
            if total:
                items.append(HTML.span(HTML.b(str(total)), **repr_attrs))
            yield Legend(
                self,
                'layers',
                items,
                label='Legend',
                stay_open=True,
                item_attrs=dict(style='clear: right'))
        items = []
        for size in [15, 20, 30, 40]:
            attrs = dict(name="iconsize", value=str(size), type="radio")
            if size == self.options.get('icon_size', 30):
                attrs['checked'] = 'checked'
            items.append(HTML.label(
                HTML.input(onclick=helpers.JS_CLLD.mapResizeIcons(self.eid), **attrs),
                HTML.img(
                    height=str(size),
                    width=str(size),
                    src=self.req.registry.getUtility(IIcon, 'cff6600').url(self.req)),
                class_="radio",
                style="margin-left: 5px; margin-right: 5px;"))
        yield Legend(
            self,
            'iconsize',
            items,
            label='Icon size')

        item = lambda layer: HTML.a(
            layer.name,
            onclick='return %s;' % helpers.JS_CLLD.mapShowGeojson(self.eid, layer.id),
            href=layer.data if isinstance(layer.data, basestring) else '#')
        yield Legend(
            self, 'geojson', map(item, self.layers), label='GeoJSON', pull_right=True)
示例#15
0
 def dl_link(self, adapter):
     return HTML.a(
         adapter.name or adapter.extension,
         href="#",
         id=self._id_prefix + adapter.extension,
         onclick="document.location.href = %s; return false;"
                 % (self.dl_url_tmpl % adapter.extension))
示例#16
0
 def format(self, item):
     if not item.gbif_url:
         return ''
     return HTML.a(HTML.img(
         width='20', src=self.dt.req.static_url('acc:static/gbif.png')),
                   item.gbif_name,
                   href=item.gbif_url)
示例#17
0
 def dl_link(self, adapter):
     return HTML.a(
         adapter.name or adapter.extension,
         href="#",
         id=self._id_prefix + adapter.extension,
         onclick="document.location.href = %s; return false;"
                 % (self.dl_url_tmpl % adapter.extension))
示例#18
0
 def toolbar(self):
     """
     """
     return HTML.div(
         button(icon('info-sign', inverted=True),
                class_='btn-info %s-cdOpener' % self.eid),
         HTML.a(
             icon('download-alt'), HTML.span(class_="caret"), **{
                 'class_': "btn dropdown-toggle",
                 'data-toggle': "dropdown",
                 'href': "#",
                 'id': "dt-dl-opener",
             }),
         HTML.ul(
             #HTML.li(HTML.a('csv', href="#")),
             *[
                 HTML.li(
                     HTML.
                     a(fmt,
                       href="#",
                       onclick=
                       "document.location.href = CLLD.DataTable.current_url"
                       "('%s', '%s'); return false;" % (self.eid, fmt),
                       id='dt-dl-%s' % fmt)) for fmt in [
                           a.extension
                           for n, a in self.req.registry.getAdapters(
                               [self.model()], IIndex)
                       ] if fmt != 'html'
             ],
             **dict(class_="dropdown-menu")),
         class_='btn-group right')
示例#19
0
def link_to_map(language):
    return HTML.a(
        icon("icon-globe"),
        title="show %s on map" % language.name,
        href="#map",
        onclick=JS_CLLD.mapShowInfoWindow(None, language.id),
    )
示例#20
0
 def __init__(self, dt, name, **kw):
     self.macroareas = DBSession.query(Macroarea).order_by(Macroarea.id).all()
     kw['bSortable'] = False
     kw['sDescription'] = HTML.span(
         'see ',
         HTML.a('glossary',
                href=dt.req.route_url('home.glossary', _anchor='macroarea')))
     super(MacroareaCol, self).__init__(dt, name, **kw)
示例#21
0
def segment_link(req, glyph, segments, ns=False):
    if glyph not in segments:
        if ns:
            return ""
        return HTML.a(glyph, name="glyph-" + glyph, style="font-size: 1em; color: lightgray;")
    res = link(req, segments[glyph])
    del segments[glyph]
    return res
示例#22
0
 def link(self, id_):
     if not id_:
         return ''
     return HTML.a(
         id_,
         title=self.collection_dict[id_].name,
         href=self.dt.req.route_url(
             self.route, _anchor='%s-%s' % (self.cls.mapper_name().lower(), id_)))
示例#23
0
def concepticon_link(request, meaning):
    return HTML.a(
        HTML.img(
            src=request.static_url('dictionaria:static/concepticon_logo.png'),
            height=20,
            width=30),
        title='corresponding concept set at Concepticon',
        href=meaning.concepticon_url)
示例#24
0
 def __init__(self, dt, name, **kw):
     self.macroareas = DBSession.query(Macroarea).order_by(Macroarea.id).all()
     kw['bSortable'] = False
     kw['sDescription'] = HTML.span(
         'see ',
         HTML.a('glossary',
                href=dt.req.route_url('home.glossary', _anchor='macroarea')))
     super(MacroareaCol, self).__init__(dt, name, **kw)
示例#25
0
def concepticon_link(request, meaning):
    return HTML.a(
        HTML.img(
            src=request.static_url('dictionaria:static/concepticon_logo.png'),
            height=20,
            width=30),
        title='corresponding concept set at Concepticon',
        href=meaning.concepticon_url)
示例#26
0
 def chunks():
     start = 0
     for match in ISO_PATTERN.finditer(text):
         yield text[start:match.start(0)]
         url = request.route_url(route_name, id=match.group('iso'))
         yield HTML.a(match.group(0), href=url, class_=class_)
         start = match.end(0)
     yield text[start:]
示例#27
0
 def formatted_refs(self, req):
     res = []
     for ref in self.references:
         text = HTML.a(ref.source.name, href=req.resource_url(ref.source))
         if ref.description:
             text = '%s: %s' % (text, ref.description)
         res.append(text)
     return '; '.join(res)
示例#28
0
文件: models.py 项目: clld/tsammalex
 def formatted_refs(self, req):
     res = []
     for ref in self.references:
         text = HTML.a(ref.source.name, href=req.resource_url(ref.source))
         if ref.description:
             text = '%s: %s' % (text, ref.description)
         res.append(text)
     return '; '.join(res)
示例#29
0
def collapsed(id_, content, button_content=None):
    return HTML.div(
        HTML.p(
            HTML.a(
                button_content or icon('plus-sign'), **{
                    'class': 'btn',
                    'data-toggle': 'collapse',
                    'data-target': '#%s' % id_
                })), HTML.div(content, id=id_, class_='collapse'))
示例#30
0
 def format(self, item):
     route_url = self.dt.req.route_url
     links = (HTML.a(d.id,
                     title=d.name,
                     href=route_url(self.route,
                                    _anchor='%s-%s' %
                                    (d.__class__.__name__.lower(), d.id)))
              for d in getattr(item, self.attr))
     return ', '.join(links)
示例#31
0
文件: util.py 项目: clld/glottolog3
def format_external_link_in_label(url, label=None):
    label = label or URL(url).domain()
    return HTML.span(
        HTML.a(
            HTML.i('', class_="icon-share icon-white"),
            label,
            href=url,
            style="color: white"),
        class_="label label-info")
示例#32
0
def segment_link(req, glyph, segments, ns=False):
    if glyph not in segments:
        if ns:
            return ''
        return HTML.a(
            glyph, name="glyph-" + glyph, style='font-size: 1em; color: lightgray;')
    res = link(req, segments[glyph])
    del segments[glyph]
    return res
示例#33
0
def feature_description(req, ctx):
    desc = ctx.markup_description or ctx.description
    desc = re.sub(
        "\*\*(?P<id>[0-9]+\-[0-9]+)\*\*",
        lambda m: HTML.a('[%s]' % m.group('id'),
                         href=req.route_url('sentence', id=m.group('id'))),
        desc)

    desc = re.sub(
        "\*\*\<\/span\>(?P<id>[0-9]+\-[0-9]+)\*\*",
        lambda m: literal('</span>') + HTML.a(
            '[%s]' % m.group('id'),
            href=req.route_url('sentence', id=m.group('id'))), desc)

    return re.sub(
        '\<span style\=\"font-style\: italic;\"\>WALS\<\/span\>\s+feature\s+[0-9]+',
        lambda m: HTML.a(literal(desc[m.start():m.end()]),
                         href=req.route_url('wals', id=ctx.id)), desc)
    def format(self, item):
        parts = []
        for i, cogid in enumerate((item.partial_cognate or '').split()):
            if i > 0:
                parts.append('+')
            parts.append(
                HTML.a(cogid,
                       href=self.dt.req.route_url('cognateset', id=cogid)))

        return HTML.span(*parts)
示例#35
0
def concepticon_link(request, concept):
    if not concept.concepticon_id:
        return ''
    return HTML.a(
        HTML.img(
            src=request.static_url('dogonlanguages:static/concepticon_logo.png'),
            height=20,
            width=30),
        title='corresponding concept set at Concepticon',
        href=concept.concepticon_url)
示例#36
0
 def format(self, item):
     item = self.get_obj(item)
     return HTML.span(
         HTML.img(width='20',
                  src=svg.data_url(svg.icon(item.jsondata['icon']))),
         ' ',
         HTML.a(item.family_name,
                href="http://glottolog.org/resource/languoid/id/" +
                item.family_id),
         style="white-space: nowrap;")
示例#37
0
def collapsed(id_, content, button_content=None):
    return HTML.div(
        HTML.p(
            HTML.a(
                button_content or icon("plus-sign"),
                **{"class": "btn", "data-toggle": "collapse", "data-target": "#%s" % id_}
            )
        ),
        HTML.div(content, id=id_, class_="collapse"),
    )
示例#38
0
def get_data_entry(context=None, request=None, **kw):
    res = []
    if not context.data_entry:  # pragma: no cover
        return None
    for r in context.data_entry.split(';'):
        for f in DBSession.query(Contributor).filter(Contributor.id == r):
            res.append(
                HTML.a(f.name,
                       href='%s/%s' % (request.route_url('contributors'), r)))
    return ', '.join(res)
示例#39
0
文件: util.py 项目: clld/apics
def feature_description(req, ctx):
    desc = ctx.markup_description or ctx.description
    desc = re.sub(
        "\*\*(?P<id>[0-9]+\-[0-9]+)\*\*",
        lambda m: HTML.a(
            '[%s]' % m.group('id'), href=req.route_url('sentence', id=m.group('id'))),
        desc)

    desc = re.sub(
        "\*\*\<\/span\>(?P<id>[0-9]+\-[0-9]+)\*\*",
        lambda m: literal('</span>') + HTML.a(
            '[%s]' % m.group('id'), href=req.route_url('sentence', id=m.group('id'))),
        desc)

    return re.sub(
        '\<span style\=\"font-style\: italic;\"\>WALS\<\/span\>\s+feature\s+[0-9]+',
        lambda m: HTML.a(
            literal(desc[m.start():m.end()]), href=req.route_url('wals', id=ctx.id)),
        desc)
示例#40
0
def tsammalex_link(request, concept):
    if not concept.tsammalex_taxon:
        return ''
    return HTML.a(
        HTML.img(
            src=request.static_url('dogonlanguages:static/tsamma.png'),
            height=20,
            width=30),
        title='corresponding taxon at Tsammalex',
        href=concept.tsammalex_url)
示例#41
0
def get_revisors(context=None, request=None, **kw):
    res = []
    if not context.revised_by:
        return None
    for r in context.revised_by.split(','):
        for f in DBSession.query(Author).filter(Author.id == r):
            res.append(
                HTML.a(f.name,
                       href='{}/{}'.format(request.route_url('contributors'),
                                           r)))
    return ', '.join(res)
示例#42
0
def alt_representations(req, rsc, doc_position='right', exclude=None):
    exclude = exclude or []
    exclude.extend(['html', 'snippet.html'])
    adapters = [
        a
        for n, a in req.registry.getAdapters([rsc], interfaces.IRepresentation)
        if a.extension not in set(exclude)
    ]
    doc = []
    for adapter in adapters:
        if adapter.__doc__:
            doc.append(HTML.dt(adapter.name or adapter.extension))
            doc.append(HTML.dd(adapter.__doc__))
    doc = HTML.div(
        HTML.p(
            """You may download alternative representations of the data on
"%s" by clicking the button """ % rsc.name, icon('download-alt')),
        HTML.dl(*doc))
    return HTML.div(
        HTML.div(
            button(
                icon('info-sign', inverted=True), **{
                    'class': ['btn-info'],
                    'id': 'rsc-dl',
                    'data-content': unicode(doc)
                }),
            HTML.a(
                icon('download-alt'), HTML.span(class_="caret"), **{
                    'class_': "btn dropdown-toggle",
                    'data-toggle': "dropdown",
                    'href': "#",
                    'id': "dt-dl-opener",
                }),
            HTML.ul(
                *[
                    HTML.li(
                        HTML.
                        a(a.name or a.extension,
                          href="#",
                          onclick="document.location.href = '%s'; return false;"
                          % req.resource_url(rsc, ext=a.extension),
                          id='dt-dl-%s' % a.extension)) for a in adapters
                ], **dict(class_="dropdown-menu")),
            class_='btn-group'),
        HTML.script(
            literal("""\
    $(document).ready(function() {
        $('#rsc-dl').clickover({
            html: true,
            title: 'Alternative representations',
            placement: '%s',
            trigger: 'click'
        });
    });""" % doc_position)))
示例#43
0
 def __init__(self, dt, name, **kw):
     ma = DBSession.query(Parameter).filter(
         Parameter.id == 'macroarea').one()
     kw['choices'] = [de.name for de in ma.domain]
     kw['bSortable'] = False
     kw['sDescription'] = HTML.span(
         'see ',
         HTML.a('glossary',
                href=dt.req.route_url('home.glossary',
                                      _anchor='macroarea')))
     super(MacroareaCol, self).__init__(dt, name, **kw)
示例#44
0
文件: base.py 项目: marctang/clld
 def format(self, item):
     obj = self.get_obj(item)
     if not obj or getattr(obj, 'latitude', None) is None:
         return ''
     return HTML.a(
         icon('icon-globe'),
         title='show %s on map' % getattr(obj, 'name', ''),
         href="#" + self.map_id,
         onclick=JS_CLLD.mapShowInfoWindow(self.map_id, obj.id),
         class_='btn',
     )
示例#45
0
文件: base.py 项目: FieldDB/clld
 def format(self, item):
     obj = self.get_obj(item)
     if not obj or getattr(obj, 'latitude', None) is None:
         return ''
     return HTML.a(
         icon('icon-globe'),
         title='show %s on map' % getattr(obj, 'name', ''),
         href="#" + self.map_id,
         onclick=JS_CLLD.mapShowInfoWindow(self.map_id, obj.id),
         class_='btn',
     )
示例#46
0
文件: util.py 项目: clld/dictionaria
def add_unit_links(req, contrib, text):
    res, pos = [], 0
    for m in MARKDOWN_LINK_PATTERN.finditer(text):
        if m.start() > pos:
            res.append(escape(text[pos:m.start()]))
        res.append(HTML.a(
            m.group('label'),
            href=req.route_url('unit', id='{0}-{1}'.format(contrib.id, m.group('uid')))))
        pos = m.end()
    if pos < len(text):
        res.append(escape(text[pos:]))
    return HTML.span(*res)
示例#47
0
def term_link(req, term, label=None):
    parts = term.split()
    if len(parts) > 1:
        # term contains white-space!
        label = label or term
        term = '_'.join(parts)
    else:
        label = label or term.replace('_', ' ')
    term = term.lower()
    return HTML.a(label,
                  title="lookup '{0}' in the glossary".format(
                      term.replace('_', ' ')),
                  href=req.route_url('terms', _anchor=term))
示例#48
0
文件: util.py 项目: clld/wold2
def term_link(req, term, label=None):
    parts = term.split()
    if len(parts) > 1:
        # term contains white-space!
        label = label or term
        term = '_'.join(parts)
    else:
        label = label or term.replace('_', ' ')
    term = term.lower()
    return HTML.a(
        label,
        title="lookup '{0}' in the glossary".format(term.replace('_', ' ')),
        href=req.route_url('terms', _anchor=term))
示例#49
0
 def link(href, label, img, alt=None):
     return HTML.li(
         HTML.a(
             HTML.img(src=req.static_url('glottolog3:static/' + img),
                      height="20",
                      width="20",
                      alt=alt or label),
             ' ',
             label,
             href=href,
             target="_blank",
             title=label,
         ))
示例#50
0
 def __init__(self, dt, name, **kw):
     self.macroareas = DBSession.query(Macroarea).order_by(
         Macroarea.id).all()
     kw['bSortable'] = False
     desc = []
     for area in self.macroareas:
         desc.append(HTML.dt(u'%s' % area))
         desc.append(HTML.dd(area.description))
     kw['sDescription'] = HTML.span(
         'see ',
         HTML.a('glossary',
                href=dt.req.route_url(
                    'home.glossary', _anchor='macroarea')))  #HTML.dl(*desc)
     super(MacroareaCol, self).__init__(dt, name, **kw)
示例#51
0
文件: helpers.py 项目: mitcho/clld
def gbs_link(source, pages=None):
    if not source.google_book_search_id or not source.jsondata or not source.jsondata.get('gbs'):
        return ''
    if source.jsondata['gbs']['accessInfo']['viewability'] in ['NO_PAGES']:
        return ''
    pg = 'PP1'
    if pages:
        match = re.search('(?P<startpage>[0-9]+)', pages)
        if match:
            pg = 'PA' + match.group('startpage')
    return HTML.a(
        HTML.img(src="https://www.google.com/intl/en/googlebooks/images/gbs_preview_button1.gif"),
        href="http://books.google.com/books?id=%s&lpg=PP1&pg=%s" % (
            source.google_book_search_id, pg)
    )
示例#52
0
def gbs_link(source, pages=None):
    """Format Google-Books information for source as HTML."""
    if not source or not source.google_book_search_id or not source.jsondata.get("gbs"):
        return ""
    if source.jsondata["gbs"]["accessInfo"]["viewability"] in ["NO_PAGES"]:
        return ""
    pg = "PP1"
    if pages:
        match = re.search("(?P<startpage>[0-9]+)", pages)
        if match:
            pg = "PA" + match.group("startpage")
    return HTML.a(
        HTML.img(src="https://www.google.com/intl/en/googlebooks/images/" "gbs_preview_button1.gif"),
        href="http://books.google.com/books?id=%s&lpg=PP1&pg=%s" % (source.google_book_search_id, pg),
    )
示例#53
0
def gbs_link(source, pages=None):
    if not source or not source.google_book_search_id \
            or not source.jsondata or not source.jsondata.get('gbs'):
        return ''
    if source.jsondata['gbs']['accessInfo']['viewability'] in ['NO_PAGES']:
        return ''
    pg = 'PP1'
    if pages:
        match = re.search('(?P<startpage>[0-9]+)', pages)
        if match:
            pg = 'PA' + match.group('startpage')
    return HTML.a(
        HTML.img(src="https://www.google.com/intl/en/googlebooks/images/"
                 "gbs_preview_button1.gif"),
        href="http://books.google.com/books?id=%s&lpg=PP1&pg=%s" %
        (source.google_book_search_id, pg))
示例#54
0
文件: helpers.py 项目: mitcho/clld
def link(req, obj, **kw):
    get_link_attrs = req.registry.queryUtility(interfaces.ILinkAttrs)
    if get_link_attrs:
        kw = get_link_attrs(req, obj, **kw)

    rsc = None
    rsc_name = kw.pop('rsc', None)
    for _rsc in RESOURCES:
        if _rsc.interface.providedBy(obj) or _rsc.name == rsc_name:
            rsc = _rsc
            break
    assert rsc
    href = kw.pop('href', req.resource_url(obj, rsc=rsc, **kw.pop('url_kw', {})))
    kw.setdefault('class', rsc.interface.__name__[1:])
    label = kw.pop('label', unicode(obj))
    kw.setdefault('title', label)
    return HTML.a(label, href=href, **kw)
示例#55
0
文件: __init__.py 项目: mitcho/clld
 def render(self):
     a_attrs = {
         'class': 'dropdown-toggle',
         'data-toggle': "dropdown",
         'href': "#",
         'id': self.format_id('opener')}
     ul_class = 'dropdown-menu'
     if self.stay_open:
         ul_class += ' stay-open'
     return HTML.li(
         HTML.a(self.label, HTML.b(class_='caret'), **a_attrs),
         HTML.ul(
             *map(self.render_item, self.items),
             **dict(class_=ul_class, id=self.format_id('container'))),
         class_='dropdown',
         id=self.format_id(),
     )
示例#56
0
def link(obj, label=None, with_mime_type=True, badge=False):
    label = label or 'View file'
    mtype = mimetype(obj)
    icon_ = MIMETYPE_TO_ICON.get(
        mtype, MIMETYPE_TO_ICON.get(maintype(obj, mimetype_=mtype), 'download-alt'))
    md = ''
    if obj.jsondata.get('size'):
        md = format_size(obj.jsondata['size'])
    if with_mime_type:
        if md:
            md += ', '
        md += mtype
    if md:
        label += ' (%s)' % md
    return HTML.a(
        HTML.span(
            icon(icon_, inverted=badge),
            ' ' + label,
            class_='badge' if badge else 'cdstar_link'),
        href=bitstream_url(obj))
示例#57
0
def link(req, obj, **kw):
    get_link_attrs = req.registry.queryUtility(interfaces.ILinkAttrs)
    if get_link_attrs:
        kw = get_link_attrs(req, obj, **kw)

    if "class_" in kw:
        kw["class"] = kw["class_"]
        del kw["class_"]

    rsc = None
    rsc_name = kw.pop("rsc", None)
    for _rsc in RESOURCES:
        if _rsc.interface.providedBy(obj) or _rsc.name == rsc_name:
            rsc = _rsc
            break
    assert rsc
    href = kw.pop("href", req.resource_url(obj, rsc=rsc, **kw.pop("url_kw", {})))
    kw["class"] = " ".join(filter(None, kw.get("class", "").split() + [rsc.interface.__name__[1:]]))
    label = kw.pop("label", text_type(obj))
    kw.setdefault("title", label)
    return HTML.a(label, href=href, **kw)