コード例 #1
0
def format_element(bfo, default = '', separator = '; ', style = '', \
           show_icons = 'no', prefix='', suffix=''):
    """ Creates html of links based on metadata
    @param separator (separates instances of links)
    @param prefix
    @param suffix
    @param show_icons default = no
    @param style options CSS style for link
    """
    _ = gettext_set_language(bfo.lang)
    if style != "":
        style = 'class = "' + style + '"'

    links = []

    from invenio.bibformat_elements.bfe_INSPIRE_arxiv import format_element as arxiv
    if show_icons.lower() == 'yes':
        mirrors = "no"
    else:
        mirrors = "yes"
    arxiv_links = arxiv(bfo, links="yes", mirrors="no")
    if arxiv_links:
        links.append(arxiv_links)

    journals = bfo.fields('773')
    # trivially take care of dois
    for journal in journals:
        oa_type = bfo.kb('OALINKS', journal.get('n'), '').lower()
        if oa_type:
            final_style = style + ' class = "' + oa_type + '"'
        else:
            final_style = style
        if journal.get('a'):
            links.append('<a '+final_style+ 'href="http://dx.doi.org/'\
                         +journal.get('a')+'">Journal Server</a>')

    # could look for other publication info and calculate URls here

    # now look for explicit URLs
    # might want to check that we aren't repeating things from above...
    # Note: excluding self-links
    urls = bfo.fields('8564_')
    links.extend(['<a '+ style + \
            'href="' + url.get("u") + '">' + \
                  _lookup_url_name(bfo, url.get('y', 'Fulltext')) +'</a>'
            for url in urls if url.get("u") and \
                  url.get('y', 'Fulltext').upper() != "DOI" and not \
                  url.get('u').startswith(CFG_SITE_URL)])

    #put it all together
    if links:
        if show_icons.lower() == 'yes':
            img = '<img style="border:none" \
            src="%s/img/file-icon-text-12x16.gif" alt="%s"/>'\
            % (CFG_SITE_URL, _("Download fulltext"))
            links = [img + '<small>' + link + '</small>' for link in links]
        return prefix + separator.join(links) + suffix
    else:
        return default
コード例 #2
0
ファイル: bfe_INSPIRE_links.py プロジェクト: traviscb/inspire
def format_element(bfo, default = '', separator = '; ', style = '', \
           show_icons = 'no', prefix='', suffix=''):
    """ Creates html of links based on metadata
    @param separator (separates instances of links)
    @param prefix
    @param suffix
    @param show_icons default = no
    @param style options CSS style for link
    """
    _ = gettext_set_language(bfo.lang)
    if style != "":
        style = 'class = "'+style+'"'

    links = []


    from invenio.bibformat_elements.bfe_INSPIRE_arxiv import format_element as arxiv
    if show_icons.lower() == 'yes':
        mirrors = "no"
    else:
        mirrors = "yes"
    arxiv_links = arxiv(bfo, links = "yes", mirrors = "no")
    if arxiv_links:
        links.append(arxiv_links)

    journals = bfo.fields('773')
    # trivially take care of dois
    for journal in journals:
        oa_type = bfo.kb('OALINKS', journal.get('n'), '').lower()
        if oa_type:
            final_style = style+' class = "'+oa_type+'"'
        else:
            final_style = style
        if journal.get('a'):
            links.append('<a '+final_style+ 'href="http://dx.doi.org/'\
                         +journal.get('a')+'">Journal Server</a>')


    # could look for other publication info and calculate URls here


    # now look for explicit URLs
    # might want to check that we aren't repeating things from above...
    # Note: excluding self-links
    urls = bfo.fields('8564_')
    links.extend(['<a '+ style + \
            'href="' + url.get("u") + '">' + \
                  _lookup_url_name(bfo, url.get('y', 'Fulltext')) +'</a>'
            for url in urls if url.get("u") and \
                  url.get('y', 'Fulltext').upper() != "DOI" and not \
                  url.get('u').startswith(CFG_SITE_URL)])




    #put it all together
    if links:
        if show_icons.lower() == 'yes':
            img = '<img style="border:none" \
            src="%s/img/file-icon-text-12x16.gif" alt="%s"/>'\
            % (CFG_SITE_URL, _("Download fulltext"))
            links = [img+'<small>'+link+'</small>' for link in links]
        return prefix+separator.join(links)+suffix
    else:
        return default
コード例 #3
0
ファイル: bfe_INSPIRE_links.py プロジェクト: jrbl/inspire-dev
def format_element(bfo, default="", separator="; ", style="", show_icons="no", prefix="", suffix=""):
    """ Creates html of links based on metadata
    @param separator (separates instances of links)
    @param prefix
    @param suffix
    @param show_icons default = no
    @param style options CSS style for link
    """
    _ = gettext_set_language(bfo.lang)
    if style != "":
        style = 'class = "' + style + '"'

    links = []

    from invenio.bibformat_elements.bfe_INSPIRE_arxiv import format_element as arxiv

    # if show_icons.lower() == 'yes':
    #    mirrors = "no"
    # else:
    #    mirrors = "yes"
    arxiv_links = arxiv(bfo, links="yes", mirrors="no")
    if arxiv_links:
        links.append(arxiv_links)

    journals = bfo.fields("773")
    # trivially take care of dois
    for journal in journals:
        journtitle = ""
        oa_type = bfo.kb("OALINKS", journal.get("n"), "").lower()
        if oa_type:
            final_style = style + ' class = "' + oa_type + '"'
        else:
            final_style = style
        if journal.get("a"):
            if journal.get("p"):
                journtitle = " - " + journal.get("p")
            links.append(
                "<a "
                + final_style
                + 'href="http://dx.doi.org/'
                + journal.get("a")
                + '">Journal Server</a>'
                + journtitle
            )

    # KEKSCAN links
    identifiers = bfo.fields("035__")

    for ident in identifiers:
        if ident["9"] == "KEKSCAN":
            out = ident["a"].replace("-", "")
            links.append('<a href="http://www-lib.kek.jp/cgi-bin/img_index?' + out + '"> KEK scanned document </a>')

    # CDS links
    identifiers = bfo.fields("035__")

    for ident in identifiers:
        if ident["9"] == "CDS":
            links.append('<a href="http://cds.cern.ch/record/' + ident["a"] + '"> CERN Document Server </a>')

    # could look for other publication info and calculate URls here

    # now look for explicit URLs
    # might want to check that we aren't repeating things from above...
    # Note: excluding self-links
    urls = bfo.fields("8564_")
    allowed_doctypes = ["INSPIRE-PUBLIC"]
    for url in urls:
        if url.get("u") and url.get("y", "Fulltext").upper() != "DOI" and not url.get("u").startswith(CFG_SITE_URL):
            links.append(
                "<a "
                + style
                + 'href="'
                + url.get("u")
                + '">'
                + _lookup_url_name(bfo, url.get("y", "Fulltext"))
                + "</a>"
            )
        elif (
            url.get("u").startswith(CFG_SITE_URL)
            and bibdocfile_url_to_bibdoc(url.get("u")).doctype in allowed_doctypes
            and url.get("u")[-3:].lower() == "pdf"
        ):
            links.append(
                "<a "
                + style
                + 'href="'
                + url.get("u")
                + '">'
                + _lookup_url_name(bfo, url.get("y", "Fulltext"))
                + "</a>"
            )

    # put it all together
    if links:
        if show_icons.lower() == "yes":
            img = (
                '<img style="border:none" \
            src="%s/img/file-icon-text-12x16.gif" alt="%s"/>'
                % (CFG_SITE_URL, _("Download fulltext"))
            )
            links = [img + "<small>" + link + "</small>" for link in links]
        return prefix + separator.join(links) + suffix
    else:
        return default