Exemplo n.º 1
0
def format(bfo,  highlight="no", force_title_case="no"):
    """
    Provides title  converts to title case (Upper Cased First Letters) if
    the title is in all caps


    """

    titles = bfo.fields('245', 1)



    out = ""


    for title in titles:
        out += title.get('a')


    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</style>')


    if force_title_case.lower()=="yes" and (out.upper()==out or re.search('THE ',out)):   #title is allcaps
        out=' '.join([word.capitalize() for word in out.split(' ')])   # should not cap 1 letter words...


    return out
def format_element(bfo,  highlight="no", force_title_case="no"):
    """
    Provides title  converts to title case (Upper Cased First Letters) if
    the title is in all caps


    """

    titles = bfo.fields('245', 1)



    out = ""


    for title in titles:
        out += title.get('a')


    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</style>')


    if force_title_case.lower()=="yes" and (out.upper()==out or re.search('THE ',out)):   #title is allcaps
        out=' '.join([word.capitalize() for word in out.split(' ')])   # should not cap 1 letter words...


    return out
Exemplo n.º 3
0
def format_element(bfo, highlight="no", force_title_case="no", brief="no", esctitle='0', oldtitles="no", mode=None):
    """
    Prints a title, with optional subtitles, and optional highlighting.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    @param force_title_case caps First Letter of Each World if set to 'yes'
    @param brief If yes, skip printing subtitles; if no, print complete title:subtitle
    @param esctitle How should escaping of titles in the database be handled?
    @param oldtitles Whether to show old titles in output
    @param mode In mode='tex' apply some TeX sequence escapes to output
    """

    out = ''
    esctitle = int(esctitle)

    titles = bfo.fields('245__', esctitle)
    old_titles = bfo.fields('246__', esctitle)

    # Concatenate all the regular titles (a) and (optionally) subtitles (b)
    for title in titles:
        out += title.get('a', '')
        if brief == "no" and title.has_key('b'):
            out += ' : ' + title['b']

    # Concatenate any old titles (a) and subtitles(b)
    if oldtitles == "yes":
        for old_title in old_titles:
            out += "<br /><b><i>" + old_title.get('a') + '</i></b>'
            if brief == "no" and old_title.has_key('b'):
                out += ' : ' + old_title['b']

    # Hilight matching words if requested
    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</span>')

    # Force title casing if requested
    if force_title_case.lower() == "yes" and (out.upper() == out or out.find('THE ') >= 0):
        #title is allcaps
        out = ' '.join([word.capitalize() for word in out.split(' ')])
        # .title() too dumb; don't cap 1 letter words


    if mode == 'tex':
        # TeX escape some common sequences
        if out.count('$') == 0:
            out = re.sub(r'(?<!\\)([_%&#])', r'\\\1', out)
            out = re.sub(r'-+&gt;', r'$\,\to\,$', out)
            out = re.sub(r'-+>', r'$\,\to\,$', out)
            out = re.sub(r'(?<!\\)\^', r'\\textasciicircum{}', out)
            greek = '|'.join(('alpha', 'beta', 'gamma', 'Gamma', 'delta', 'Delta', 'epsilon',
                              'zeta', 'eta', 'theta', 'Theta', 'kappa', 'lambda', 'Lambda',
                              'mu', 'nu', 'xi', 'Xi', 'pi', 'Pi', 'rho', 'sigma', 'Sigma',
                              'tau', 'upsilon', 'Upsilon', 'phi', 'Phi', 'chi', 'psi', 'Psi',
                              'omega', 'Omega'))
            out = re.sub(r'\\(' +  greek + r')\b', r'$\\\1$', out)
    return out
Exemplo n.º 4
0
def format_element(bfo, separator=" ", highlight='no'):
    """
    Prints the titles of a record.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    titles = []

    title = bfo.field('245__a')
    title_remainder = bfo.field('245__b')
    edition_statement = bfo.field('250__a')
    title_tome = bfo.field('245__n')
    title_part = bfo.field('245__p')

    if len(title) > 0:
        if title_remainder:
            title += ': ' + title_remainder
        if len(title_tome) > 0:
            title += ", " + title_tome
        if len(title_part) > 0:
            title += ": " + title_part
        titles.append(title)

    title = bfo.field('0248_a')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246__a')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246__b')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246_1a')
    if len(title) > 0:
        titles.append(title)

    if len(titles) > 0:
        #Display 'Conference' title only if other titles were not found
        title = bfo.field('111__a')
        if len(title) > 0:
            titles.append(title)

    titles = [cgi.escape(x) for x in titles]

    if highlight == 'yes':
        from invenio import bibformat_utils
        titles = [
            bibformat_utils.highlight(x, bfo.search_pattern) for x in titles
        ]

    if len(edition_statement) > 0:
        return separator.join(titles) + "; " + edition_statement
    else:
        return separator.join(titles)
Exemplo n.º 5
0
def format_element(bfo, separator=" ", highlight="no"):
    """
    Prints the titles of a record.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    titles = []

    title = bfo.field("245__a")
    title_remainder = bfo.field("245__b")
    edition_statement = bfo.field("250__a")
    title_tome = bfo.field("245__n")
    title_part = bfo.field("245__p")

    if len(title) > 0:
        if title_remainder:
            title += ": " + title_remainder
        if len(title_tome) > 0:
            title += ", " + title_tome
        if len(title_part) > 0:
            title += ": " + title_part
        titles.append(title)

    title = bfo.field("0248_a")
    if len(title) > 0:
        titles.append(title)

    title = bfo.field("246__a")
    if len(title) > 0:
        titles.append(title)

    title = bfo.field("246__b")
    if len(title) > 0:
        titles.append(title)

    title = bfo.field("246_1a")
    if len(title) > 0:
        titles.append(title)

    if len(titles) > 0:
        # Display 'Conference' title only if other titles were not found
        title = bfo.field("111__a")
        if len(title) > 0:
            titles.append(title)

    titles = [cgi.escape(x) for x in titles]

    if highlight == "yes":
        from invenio import bibformat_utils

        titles = [bibformat_utils.highlight(x, bfo.search_pattern) for x in titles]

    if len(edition_statement) > 0:
        return separator.join(titles) + "; " + edition_statement
    else:
        return separator.join(titles)
Exemplo n.º 6
0
def render_authors(bfo,
                   authors_list,
                   limit,
                   separator='; ',
                   extension='[...]',
                   print_links="yes",
                   print_affiliations='no',
                   affiliation_prefix=' (',
                   affiliation_suffix=')',
                   interactive="no",
                   highlight="no",
                   prefix=""):

    _ = gettext_set_language(bfo.lang)
    nb_authors = len(authors_list)

    for author in authors_list:
        if highlight == 'yes':
            author['a'] = bibformat_utils.highlight(author['a'],
                                                    bfo.search_pattern)
        if print_links.lower() == "yes":
            author['a'] = '<a href="%s/search?f=author&amp;p=%s&amp;ln=%s">%s</a>' % \
                          (CFG_SITE_URL, quote(author['a']), bfo.lang, escape(author['a']))
        if author.has_key('u') and print_affiliations == "yes":
            author['u'] = affiliation_prefix + author['u'] + affiliation_suffix
            author['a'] = author.get('a', '') + author.get('u', '')

    authors = []

    for author in authors_list:
        if author.has_key('q'):
            authors.append(author['a'] + " (" + author['q'] + ")")
        else:
            authors.append(author['a'])

    #authors = [author['a'] for author in authors_list] #James: have to put a condition to know if a q argument exist

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return prefix + separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        return """%s%s<br />
                  <div class="toggler"><a href="#">%s</a></div>
                  <div class="toggled" style="display:none">%s</div>""" % (
            prefix, separator.join(
                authors[:int(limit)]), _("Show all %i authors") % nb_authors,
            separator.join(authors[int(limit):]))
    else:
        return prefix + separator.join(authors)
Exemplo n.º 7
0
def format_element(bfo, separator=" ", highlight='no'):
    """
    Prints the meeting information.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    meeting = []

    name = bfo.field('1112_a')
    session_no = bfo.field('1112_n')
    date = bfo.field('1112_d')
    place = bfo.field('1112_c')
    rnum1 = bfo.field('4901_a')
    rnum2 = bfo.field('4901_v')
    rnum3 = bfo.field('4901_x')

    if len(name) == 0:
        name = bfo.field('7112_a')
    if len(session_no) == 0:
        session_no = bfo.field('7112_n')
    if len(date) == 0:
        date = bfo.field('7112_d')
    if len(place) == 0:
        place = bfo.field('7112_c')

    if len(name) > 0:
        meeting.append(name)
    if len(session_no) > 0:
        meeting.append(session_no)
    if len(date) > 0:
        meeting.append(date)
    if len(place) > 0:
        meeting.append(place)
    if len(rnum1) > 0:
        meeting.append(rnum1)
    if len(rnum2) > 0:
        meeting.append(rnum2)
    if len(rnum3) > 0:
        meeting.append(rnum3)

    meeting = [cgi.escape(x) for x in meeting]

    if highlight == 'yes':
        from invenio import bibformat_utils
        meeting = [bibformat_utils.highlight(x, bfo.search_pattern) for x in meeting]

    return separator.join(meeting)
Exemplo n.º 8
0
def format_element(bfo, highlight="no", force_title_case="no", brief="no", esctitle='0', oldtitles="no"):
    """
    Prints a title, with optional subtitles, and optional highlighting.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    @param force_title_case caps First Letter of Each World if set to 'yes'
    @param brief If yes, skip printing subtitles; if no, print complete title:subtitle
    @param esctitle How should escaping of titles in the database be handled?
    @param oldtitles Whether to show old titles in output
    """

    out = ''
    esctitle = int(esctitle)

    titles = bfo.fields('245__', esctitle)
    old_titles = bfo.fields('246__', esctitle)

    # Concatenate all the regular titles (a) and (optionally) subtitles (b)
    for title in titles:
        out += title.get('a', '')
        if brief == "no" and title.has_key('b'):
            out += ' : ' + title['b']

    # Concatenate any old titles (a) and subtitles(b)
    if oldtitles == "yes":
        for old_title in old_titles:
            out += "<br /><b><i>" + old_title.get('a') + '</i></b>'
            if brief == "no" and old_title.has_key('b'):
                out += ' : ' + old_title['b']

    # Hilight matching words if requested
    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</span>')

    # Force title casing if requested
    if force_title_case.lower()=="yes" and (out.upper()==out or out.find('THE ')>=0):   #title is allcaps
        out=' '.join([word.capitalize() for word in out.split(' ')])   # .title() too dumb; don't cap 1 letter words

    return out
Exemplo n.º 9
0
def format_element(bfo, highlight="no", multilang='no'):
    """
    Prints a short title, suitable for brief format.

    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    if multilang == 'yes':
        if bfo.lang == 'fr':
            title = bfo.field('246_1a')
        else:
            title = bfo.field('245__a')
    else:
        title = bfo.field('245__a')
    title_remainder = bfo.field('245__b')
    title_tome = bfo.field('245__n')
    title_part = bfo.field('245__p')
    edition_statement = bfo.field('250__a')

    out = title
    if len(title_remainder) > 0:
        out += ": " + title_remainder
    if len(edition_statement) > 0:
        out += "; " + edition_statement
    if len(title_tome) > 0:
        out += ", " + title_tome
    if len(title_part) > 0:
        out += ": " + title_part

    #Try to display 'Conference' title if other titles were not found
    if out == '':
        out += bfo.field('111__a')

    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(
            out,
            bfo.search_pattern,
            prefix_tag="<span style='font-weight: bolder'>",
            suffix_tag='</style>')

    return out
Exemplo n.º 10
0
def format(bfo, highlight="no", multilang='no'):
    """
    Prints a short title, suitable for brief format.

    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    if multilang == 'yes':
        if bfo.lang == 'fr':
            title = bfo.field('246_1a')
        else:
            title = bfo.field('245__a')
    else:
        title = bfo.field('245__a')
    title_remainder = bfo.field('245__b')
    title_tome = bfo.field('245__n')
    title_part = bfo.field('245__p')
    edition_statement = bfo.field('250__a')

    out = title
    if len(title_remainder) > 0:
        out += ": " + title_remainder
    if len(edition_statement) > 0:
        out += "; " + edition_statement
    if len(title_tome) > 0:
        out += ", " + title_tome
    if len(title_part) > 0:
        out += ": " + title_part

    #Try to display 'Conference' title if other titles were not found
    if out == '':
        out += bfo.field('111__a')

    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</style>')

    return out
Exemplo n.º 11
0
def format_element(bfo, limit, separator=' ; ',
           extension='[...]',
           print_links="yes",
           print_affiliations='no',
           affiliation_prefix=' (',
           affiliation_suffix=')',
           interactive="no",
           highlight="no",
           link_author_pages="no",
           relator_code_pattern=None):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param relator_code_pattern: a regular expression to filter authors based on subfield $4 (relator code)
    """
    _ = gettext_set_language(bfo.lang)    # load the right message language

    authors = []
    authors_1 = bfo.fields('100__')
    authors_2 = bfo.fields('700__')

    authors.extend(authors_1)
    authors.extend(authors_2)

    if relator_code_pattern:
        p = re.compile(relator_code_pattern)
        authors = filter(lambda x: p.match(x.get('4', '')), authors)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if author.has_key('a'):
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            if print_links.lower() == "yes":
                if link_author_pages == "no":
                    author['a'] = '<a itemprop="creator" href="' + CFG_SITE_URL + \
                                  '/search?f=author&amp;p=' + quote(author['a']) + \
                                  '&amp;ln=' + bfo.lang + \
                                  '" ><span itemscope itemtype="http://schema.org/Person"><span itemprop="name">' + escape(author['a']) + '</span></span></a>'
                else:
                    author['a'] = '<a itemprop="creator" rel="author" href="' + CFG_SITE_URL + \
                                  '/author/' + quote(author['a']) + \
                                  '?recid=' +  bibrec_id + \
                                  '&ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'

        if author.has_key('u'):
            if print_affiliations == "yes":
                author['u'] = affiliation_prefix + '<span itemprop="affiliation">' + author['u'] + \
                              '<span>' + affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [author.get('a', '') + author.get('u', '')
                   for author in authors]
    else:
        authors = [author.get('a', '')
                   for author in authors]

    if limit.isdigit() and  nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more_%s" style="">' % bibrec_id + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension_%s"></span>' % bibrec_id
        out += ' <small><i><a id="link_%s" href="#" style="color:rgb(204,0,0);"></a></i></small>' % bibrec_id
        out += '''
        <script type="text/javascript">
        $('#link_%(recid)s').click(function(event) {
            event.preventDefault();
            var more = document.getElementById('more_%(recid)s');
            var link = document.getElementById('link_%(recid)s');
            var extension = document.getElementById('extension_%(recid)s');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        });

        function set_up_%(recid)s(){
            var extension = document.getElementById('extension_%(recid)s');
            extension.innerHTML = "%(extension)s";
            $('#link_%(recid)s').click();
        }

        </script>
        ''' % {'show_less':_("Hide"),
             'show_more':_("Show all %i authors") % nb_authors,
             'extension':extension,
             'recid': bibrec_id}
        out += '<script type="text/javascript">set_up_%s()</script>' % bibrec_id

        return out
    elif nb_authors > 0:
        return separator.join(authors)
def format_element(bfo, limit, separator=', ',
           extension='[...]',
           print_links="yes",
           print_affiliations='no',
           affiliation_prefix=' (',
           affiliation_suffix=')',
           interactive="no",
           highlight="no",
           link_author_pages="no"):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    """
    from urllib import quote
    from cgi import escape
    from invenio.config import CFG_SITE_URL
    from invenio.messages import gettext_set_language

    _ = gettext_set_language(bfo.lang)    # load the right message language

    authors = []
    authors_2 = bfo.fields('65017')

    authors.extend(authors_2)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if author.has_key('a'):
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

        if author.has_key('a'):
            if print_affiliations == "yes":
                author['a'] = affiliation_prefix + author['a'] + \
                              affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [author.get('a', '') + author.get('a', '')
                   for author in authors]
    else:
        authors = [author.get('a', '')
                   for author in authors]

    if limit.isdigit() and  nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '''
        <script type="text/javascript">
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = "%(extension)s";
            toggle_authors_visibility();
        }

        </script>
        ''' % {'show_less':_("Hide"),
             'show_more':_("Show all %i authors") % nb_authors,
             'extension':extension}

        out += '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more" style="">' + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a id="link" href="#" onclick="toggle_authors_visibility()" style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script type="text/javascript">set_up()</script>'
        return out
    elif nb_authors > 0:
        return separator.join(authors)
Exemplo n.º 13
0
def format_element(bfo,
                   highlight="no",
                   force_title_case="no",
                   brief="no",
                   esctitle='0',
                   oldtitles="no",
                   mode=None):
    """
    Prints a title, with optional subtitles, and optional highlighting.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    @param force_title_case caps First Letter of Each World if set to 'yes'
    @param brief If yes, skip printing subtitles; if no, print complete title:subtitle
    @param esctitle How should escaping of titles in the database be handled?
    @param oldtitles Whether to show old titles in output
    @param mode In mode='tex' apply some TeX sequence escapes to output
    """

    out = ''
    esctitle = int(esctitle)

    titles = bfo.fields('245__', esctitle)
    old_titles = bfo.fields('246__', esctitle)

    # Concatenate all the regular titles (a) and (optionally) subtitles (b)
    for title in titles:
        out += title.get('a', '')
        if brief == "no" and title.has_key('b'):
            out += ' : ' + title['b']

    # Concatenate any old titles (a) and subtitles(b)
    if oldtitles == "yes":
        for old_title in old_titles:
            out += "<br /><b><i>" + old_title.get('a') + '</i></b>'
            if brief == "no" and old_title.has_key('b'):
                out += ' : ' + old_title['b']

    # Hilight matching words if requested
    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(
            out,
            bfo.search_pattern,
            prefix_tag="<span style='font-weight: bolder'>",
            suffix_tag='</span>')

    # Force title casing if requested
    if force_title_case.lower() == "yes":
        uout = out.decode('utf-8')
        if uout.upper() == uout or uout.find('THE ') >= 0:
            #title is allcaps
            uout = u' '.join([word.capitalize() for word in uout.split(' ')])
            # .title() too dumb; don't cap 1 letter words
        out = uout.encode('utf-8')

    if mode == 'tex':
        # TeX escape some common sequences
        if out.count('$') == 0:
            out = re.sub(r'(?<!\\)([_%&#])', r'\\\1', out)
            out = re.sub(r'-+&gt;', r'$\,\to\,$', out)
            out = re.sub(r'-+>', r'$\,\to\,$', out)
            out = re.sub(r'(?<!\\)\^', r'\\textasciicircum{}', out)
            greek = '|'.join(
                ('alpha', 'beta', 'gamma', 'Gamma', 'delta', 'Delta',
                 'epsilon', 'zeta', 'eta', 'theta', 'Theta', 'kappa', 'lambda',
                 'Lambda', 'mu', 'nu', 'xi', 'Xi', 'pi', 'Pi', 'rho', 'sigma',
                 'Sigma', 'tau', 'upsilon', 'Upsilon', 'phi', 'Phi', 'chi',
                 'psi', 'Psi', 'omega', 'Omega'))
            out = re.sub(r'\\(' + greek + r')\b', r'$\\\1$', out)
    return out
Exemplo n.º 14
0
def format_element(
        bfo, limit, separator='; ',
        extension='[...]',
        print_links="yes",
        print_affiliations='no',
        affiliation_prefix=' (',
        affiliation_suffix=')',
        print_affiliation_first='no',
        interactive="no",
        highlight="no",
        affiliations_separator=" ; ",
        name_last_first="yes",
        collaboration="yes",
        id_links="no",
        markup="html",
        link_extension="no",
):

    """
    Prints the list of authors of a record.

    @param limit the maximum number of authors to display
    @param separator the separator between authors.
    @param extension a text printed if more authors than 'limit' exist
    @param print_links if yes, prints the authors as HTML link to their
           publications
    @param print_affiliations if yes, make each author name followed by
           its affiliation
    @param affiliation_prefix prefix printed before each affiliation
    @param affiliation_suffix suffix printed after each affiliation
    @param print_affiliation_first if 'yes', affiliation is printed before
           the author
    @param interactive if yes, enable user to show/hide authors when there
           are too many (html + javascript)
    @param highlight highlights authors corresponding to search query if set
           to 'yes'
    @param affiliations_separator separates affiliation groups
    @param name_last_first if yes (default) print last, first  otherwise
           print first last
    @param collaboration if yes (default) uses collaboration name in place
           of long author list, if available
    @param id_links if yes (default = no) prints link based on INSPIRE IDs
           if available - only used if print_links = yes
    @param markup html (default) or latex or bibtex controls small markup
           differences
    @param link_extension if 'yes' link the extension to the detailed
           record page

    """
    from urllib import quote
    from cgi import escape
    import re
    from invenio.messages import gettext_set_language
    from invenio.config import CFG_SITE_RECORD

    try:
        from invenio.config import CFG_BASE_URL
    except ImportError:
        from invenio.config import CFG_SITE_URL
        CFG_BASE_URL = CFG_SITE_URL

    _ = gettext_set_language(bfo.lang)    # load the right message language

    # regex for parsing last and first names and initials
    re_last_first = re.compile(
        r'^(?P<last>[^,]+)\s*,\s*(?P<first_names>[^\,]*)(?P<extension>\,?.*)$')
    re_initials = re.compile(r'(?P<initial>\w)([\w`\']+)?.?\s*', re.UNICODE)
    re_tildehyph = re.compile(
        ur'(?<=\.)~(?P<hyphen>[\u002D\u00AD\u2010-\u2014-])(?=\w)', re.UNICODE)
    re_coll = re.compile(r'\s*collaborations?', re.IGNORECASE)

    bibrec_id = bfo.control_field("001")
    authors = []
    lastauthor = ''
    only_corporate_author = False
    authors = bfo.fields('100__', repeatable_subfields_p=True)
    authors.extend(bfo.fields('700__', repeatable_subfields_p=True))

    # If there are no authors check for corporate author in 110__a field
    if len(authors) == 0:
        authors = bfo.fields('110__', repeatable_subfields_p=True)
        if len(authors) > 0:
            only_corporate_author = True
        # For corporate authors we don't want to reverse names order
        name_last_first = 'yes'
        # And we don't want to create links
        print_links = 'no'

    # authors is a list of dictionaries, count only those with names
    # e.g. naive count of this
    # [{'a': ['Toge, Nobu']},
    #  {'u': ['Kek, High Energy Accelerator Research Organization']},
    #  {'u': ['1-1 Oho, Tsukuba-Shi, Ibaraki-Ken, 305 Japan']}]
    # would be 3, but there is only 1 author
    nb_authors = len([au for au in authors if 'a' in au])

    if markup == 'bibtex':
        # skip editors
        authors = [au for au in authors if 'a' in au
                   and not ('e' in au and 'ed.' in au['e'])]
        nb_authors = len(authors)

    # Limit num of authors, so that we do not process
    # the authors that will not be shown. This can only
    # be done in non-interactive mode, as interactive mode
    # allows to show all of them.
    if limit.isdigit() and nb_authors > int(limit) \
            and interactive != "yes":
        authors = authors[:1]

    # Process authors to add link, affiliation and highlight
    for author in authors:
        if 'a' in author:
            # There should not be repeatable subfields here
            author['a'] = author['a'][0]
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            # check if we need to reverse last, first
            # we don't try to reverse it if it isn't stored with a comma.
            first_last_match = re_last_first.search(author['a'])
            author['display'] = author['a']

            if name_last_first.lower() == "no":
                if first_last_match:
                    author['display'] = "%s %s%s" % (
                        first_last_match.group('first_names'),
                        first_last_match.group('last'),
                        first_last_match.group('extension'),)

            # for latex we do initials only (and assume first last)
            if markup == 'latex':
                if first_last_match:
                    first = re_initials.sub(
                        r'\g<initial>.~',
                        unicode(first_last_match.group('first_names'), 'utf8'))
                    first = re_tildehyph.sub(r'\g<hyphen>', first)
                    author['display'] = first + \
                        first_last_match.group('last') + \
                        first_last_match.group('extension')

            # custom name handling for bibtex
            if markup == 'bibtex':
                if first_last_match:
                    junior = first_last_match.group('extension')
                    if re.search(r'\b([JS]r\.)?$', junior) or \
                            re.search('([IV]{2,})$', junior):
                        author['display'] = "%s%s, %s" % (
                            first_last_match.group('last'),
                            junior,
                            first_last_match.group('first_names'),)
                    else:
                        author['display'] = "%s, %s%s" % (
                            first_last_match.group('last'),
                            first_last_match.group('first_names'),
                            junior,)

                    # avoid trailing comma for single name author
                    author['display'] = author['display'].rstrip(', ')

                    # multi-letter initial (in particular Russian Yu., Ya. ...)
                    # http://usefulenglish.ru/vocabulary/russian-names-in-english-en
                    author['display'] = re.sub(
                        r'\bY([aeou])\.',
                        r'{\\relax Y\1}.', author['display'])

            if print_links.lower() == "yes":
                # if there is an ID, search using that.
                id_link = ''
                if id_links == "yes" and 'i' in author:
                    author['i'] = author['i'][0]  # possible to have more IDs?
                    id_link = '<a class="authoridlink" href="' + \
                              CFG_BASE_URL + \
                              '/search?ln=' + bfo.lang + \
                              '&amp;p=100__i:' + escape(author['i']) + \
                              '+or+700__i:' + escape(author['i']) +\
                              '">' + escape("(ID Search)") + '</a> '

                author['display'] = '<a class="authorlink" href="' + \
                                    CFG_BASE_URL + \
                                    '/author/profile/' + quote(author['a']) + \
                                    '?recid=' + bibrec_id + \
                                    '&amp;ln=' + bfo.lang + \
                                    '">' + escape(author['display'])+'</a>' + \
                                    id_link

        if print_affiliations == "yes":
            if 'e' in author:
                author['e'] = affiliation_prefix + \
                    affiliations_separator.join(author['e']) + \
                    affiliation_suffix

            if 'u' in author:
                author['ilink'] = [
                    '<a class="afflink" href="' +
                    CFG_BASE_URL +
                    '/search?cc=Institutions&amp;p=institution:' +
                    quote('"' + string + '"') +
                    '&amp;ln=' + bfo.lang +
                    '">' +
                    string.lstrip() +
                    '</a>' for string in author['u']
                ]
                author['u'] = affiliation_prefix + \
                    affiliations_separator.join(author['ilink']) + \
                    affiliation_suffix

#
#  Consolidate repeated affiliations
#

    last = ''
    authors.reverse()
    for author in authors:
        if 'u' not in author:
            author['u'] = ''
        #print 'this->'+ author['a']+'\n'
        if last == author['u']:
            author['u'] = ''
        else:
            last = author['u']

    authors.reverse()

    # Flatten author instances
    if print_affiliations == 'yes':
        # 100__a (100__e)  700__a (100__e) (100__u)
        if print_affiliation_first.lower() != 'yes':
            authors = [author.get('display', '') + author.get('e', '') +
                       author.get('u', '') for author in authors]
        else:
            authors = [author.get('u', '') + author.get('display', '')
                       for author in authors]
    else:
        authors = [author.get('display', '')
                   for author in authors if 'display' in author]

    # link the extension to detailed record
    if link_extension == 'yes' and interactive != 'yes':
        extension = '<a class="authorlink" href="' +  \
            CFG_BASE_URL + '/' + CFG_SITE_RECORD + '/' + str(bfo.recID) \
            + '">' + extension + '</a>'

    # Detect Collaborations:
    if collaboration == "yes":
        colls = []
        for coll in bfo.fields("710__g"):
            if coll not in colls:
                colls.append(coll)
    else:
        colls = []

    if colls:
        short_coll = False
        colls = [re_coll.sub('', coll) for coll in colls]
        if print_links.lower() == "yes":
            colls = ['<a class="authorlink" href="' +
                     CFG_BASE_URL + '/search' +
                     '?p=collaboration:' + quote("'" + coll + "'") +
                     '&amp;ln=' + bfo.lang +
                     '">'+escape(coll)+'</a>' for coll in colls]

        coll_display = " and ".join(colls)
        if not coll_display.endswith("aboration"):
            coll_display += " Collaboration"
            if len(colls) > 1:
                coll_display += 's'
        if nb_authors > 1:
            if markup in ('latex', 'bibtex'):
                coll_display = authors[0] + extension + " [" + \
                    coll_display + "]"
            elif interactive == "yes":
                coll_display += " (" + authors[0] + " "
                extension += ")"
            else:  # html
                coll_display += " (" + authors[0] + extension + ")"
        elif nb_authors == 1:
            short_coll = True
            if markup in ('latex', 'bibtex'):
                coll_display = authors[0] + " [" + coll_display + "]"
            else:  # html
                if not only_corporate_author:
                    coll_display += " (" + authors[0] + \
                                    " for the collaboration)"
        elif nb_authors == 0:
            short_coll = True
            if markup in ('latex', 'bibtex'):
                coll_display = "[" + coll_display + "]"

    # Start outputting, depending on options and number of authors
    if colls and (interactive != "yes" or short_coll):
        return coll_display

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + lastauthor + \
            extension

    elif interactive == "yes" and \
            ((colls and not short_coll) or
             (limit.isdigit() and nb_authors > int(limit))):
        out = '''
        <script>
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = '%(extension)s';
            toggle_authors_visibility();
        }

        </script>
        ''' % {'show_less': _("Hide"),
               'show_more': _("Show all %i authors") % nb_authors,
               'extension': extension}

#        out += '<a name="show_hide" />'
        if colls:
            show = coll_display
            more = separator + separator.join(authors[1:]) + ')'
        else:
            show = separator.join(authors[:int(limit)])
            more = separator.join(authors[int(limit):len(authors)])

        out += show
        out += ' <span id="more" style="">' + more + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a id="link" href="#"' + \
               ' style="color:green;background:white;" onclick="toggle_authors_visibility()" ' + \
               ' style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script>set_up()</script>'
        return out
    elif nb_authors > 0:
        if markup in ('latex', 'bibtex'):
            if nb_authors > 1:
                lastauthor = ' and ' + authors.pop()
        return separator.join(authors) + lastauthor
Exemplo n.º 15
0
def format_element(bfo,
                   limit,
                   separator=' ; ',
                   extension='[...]',
                   print_links="no",
                   print_affiliations='no',
                   affiliation_prefix=' (',
                   affiliation_suffix=')',
                   interactive="no",
                   highlight="no"):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    """
    from urllib import quote
    from cgi import escape
    from invenio.config import CFG_SITE_URL
    from invenio.messages import gettext_set_language
    import re

    _ = gettext_set_language(bfo.lang)  # load the right message language

    authors = []
    authors_1 = bfo.fields('1001_')
    authors_2 = bfo.fields('7001_')
    authors_3 = bfo.fields('1101_')
    authors_4 = bfo.fields('1102_')
    authors_5 = bfo.fields('7102_')
    authors_6 = bfo.fields('7101_')

    authors.extend(authors_1)
    authors.extend(authors_2)
    authors.extend(authors_3)
    authors.extend(authors_4)
    authors.extend(authors_5)
    authors.extend(authors_6)

    nb_authors = len(authors)

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if author.has_key('a'):
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(
                    author['a'], bfo.search_pattern)

            # VS hack to take away links from corporate authors
            if print_links.lower() == "yes":
                if author['a'].startswith('CORP'):
                    author['a'] = re.sub('^CORP', '', author['a'])
                else:
                    author['a'] = '<a  class="detailsAuthors" href="' + CFG_SITE_URL + \
                                  '/search?f=author&amp;p='+ quote(author['a']) + \
                                  '&amp;ln='+ bfo.lang + \
                                  '">'+escape(author['a'])+'</a>'

        if author.has_key('u'):
            if print_affiliations == "yes":
                author['u'] = affiliation_prefix + author['u'] + \
                              affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [
            author.get('a', '') + author.get('u', '') for author in authors
        ]
    else:
        authors = [author.get('a', '') for author in authors]

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '''
        <script type="text/javascript">
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = "%(extension)s";
            toggle_authors_visibility();
        }

        </script>
        ''' % {
            'show_less': _("Hide"),
            'show_more': _("Show all %i authors") % nb_authors,
            'extension': extension
        }

        out += '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more" style="">' + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a class="detailsAuthors" id="link" href="#" onclick="toggle_authors_visibility()" style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script type="text/javascript">set_up()</script>'
        return out
    elif nb_authors > 0:
        return separator.join(authors)
Exemplo n.º 16
0
def format(bfo, highlight="no", force_title_case="no"):
    """
    Prints a short title, suitable for brief format.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    """

    main_corporate_authors = bfo.fields("931__a", 1)
    titles = bfo.fields("245__", 1)
    sections = bfo.fields("246__", 1)
    field_245_0 = bfo.fields("245_0", 1)
    field_245_1 = bfo.fields("245_1", 1)
    field_245_2 = bfo.fields("245_2", 1)
    field_245_3 = bfo.fields("245_3", 1)
    field_245_4 = bfo.fields("245_4", 1)
    field_245_5 = bfo.fields("245_5", 1)
    field_245_X = []
    field_245_X.extend(field_245_0)
    field_245_X.extend(field_245_1)
    field_245_X.extend(field_245_2)
    field_245_X.extend(field_245_3)
    field_245_X.extend(field_245_4)
    field_245_X.extend(field_245_5)

    alt_titles = bfo.fields("246_1", 1)
    edition_statement = bfo.field("250__a", 1)

    out = ""

    if len(main_corporate_authors) > 0:  # Why is this here?
        out += " : ".join(main_corporate_authors) + " : "

    for title in titles:
        out += title.get("a")
        if title.has_key("b"):
            out += " : " + title["b"]
        if title.has_key("s"):
            out += " : " + title["s"]

    for section in sections:
        if section.has_key("n"):
            out += " " + section["n"]
            if section.has_key("p"):
                out += " : " + section["p"]

    for inst in field_245_X:
        out += inst.get("a")
        if inst.has_key("b"):
            out += " : " + inst["b"]
        if inst.has_key("s"):
            out += " : " + inst["s"]

    for alt_title in alt_titles:
        out += "<br /><b><i>" + alt_title.get("a") + "</i></b>"
        if alt_title.has_key("b"):
            out += " : " + alt_title["b"]
        if alt_title.has_key("s"):
            out += " : " + alt_title["s"]

    # Try to display edition statement if other titles were not found
    if out == "" and edition_statement != "":
        out += " ; " + edition_statement

    if highlight == "yes":
        from invenio import bibformat_utils

        out = bibformat_utils.highlight(
            out, bfo.search_pattern, prefix_tag="<span style='font-weight: bolder'>", suffix_tag="</style>"
        )

    if force_title_case.lower() == "yes" and (out.upper() == out or re.search("THE ", out)):  # title is allcaps
        out = " ".join([word.capitalize() for word in out.split(" ")])  # should not cap 1 letter words...

    if bfo.field("960__a") == "40":
        out += "<br />"
    return out
Exemplo n.º 17
0
def format_element(bfo, limit, separator=' ; ',
                   extension='[...]',
                   print_links="yes",
                   print_affiliations='no',
                   affiliation_prefix=' (',
                   affiliation_suffix=')',
                   interactive="no",
                   highlight="no",
                   link_author_pages="no",
                   relator_code_pattern=None):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param relator_code_pattern: a regular expression to filter authors based on subfield $4 (relator code)
    """
    _ = gettext_set_language(bfo.lang)    # load the right message language

    CFG_SITE_URL = current_app.config['CFG_SITE_SECURE_URL']
    if isinstance(CFG_SITE_URL, six.text_type):
        CFG_SITE_URL = CFG_SITE_URL.encode('utf8')

    authors = []
    authors_1 = bfo.fields('100__')
    authors_2 = bfo.fields('700__')

    authors.extend(authors_1)
    authors.extend(authors_2)

    if relator_code_pattern:
        p = re.compile(relator_code_pattern)
        authors = filter(lambda x: p.match(x.get('4', '')), authors)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if 'a' in author:
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            if print_links.lower() == "yes":
                if link_author_pages == "no":
                    author['a'] = '<a itemprop="creator" href="' + \
                                  '/search?f=author&amp;p=' + quote(author['a']) + \
                                  '&amp;ln=' + str(bfo.lang) + \
                                  '" ><span itemscope itemtype="http://schema.org/Person"><span itemprop="name">' + \
                        escape(
                            author['a']) + '</span></span></a>'
                else:
                    author['a'] = '<a itemprop="creator" rel="author" href="' + \
                                  '/author/' + quote(author['a']) + \
                                  '?recid=' + bibrec_id + \
                                  '&ln=' + str(bfo.lang) + \
                                  '">' + escape(author['a']) + '</a>'

        if 'u' in author:
            if print_affiliations == "yes":
                author['u'] = affiliation_prefix + '<span itemprop="affiliation">' + author['u'] + \
                    '<span>' + affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [author.get('a', '') + author.get('u', '')
                   for author in authors]
    else:
        authors = [author.get('a', '')
                   for author in authors]

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more_%s" style="">' % bibrec_id + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension_%s"></span>' % bibrec_id
        out += ' <small><i><a id="link_%s" href="#" style="color:rgb(204,0,0);"></a></i></small>' % bibrec_id
        out += '''
        <script type="text/javascript">
        $('#link_%(recid)s').click(function(event) {
            event.preventDefault();
            var more = document.getElementById('more_%(recid)s');
            var link = document.getElementById('link_%(recid)s');
            var extension = document.getElementById('extension_%(recid)s');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        });

        function set_up_%(recid)s(){
            var extension = document.getElementById('extension_%(recid)s');
            extension.innerHTML = "%(extension)s";
            $('#link_%(recid)s').click();
        }

        </script>
        ''' % {
            'show_less': _("Hide"),
            'show_more': _("Show all %(x_num)i authors", x_num=nb_authors),
            'extension': extension,
            'recid': bibrec_id}
        out += '<script type="text/javascript">set_up_%s()</script>' % bibrec_id

        return out
    elif nb_authors > 0:
        return separator.join(authors)
def format_element(bfo, highlight="no", force_title_case="no"):
    """
    Prints a short title, suitable for brief format.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    """

    main_corporate_authors = bfo.fields('931__a', 1)
    titles = bfo.fields('245__', 1)
    sections =  bfo.fields('246__', 1)
    field_245_0 = bfo.fields('245_0', 1)
    field_245_1 = bfo.fields('245_1', 1)
    field_245_2 = bfo.fields('245_2', 1)
    field_245_3 = bfo.fields('245_3', 1)
    field_245_4 = bfo.fields('245_4', 1)
    field_245_5 = bfo.fields('245_5', 1)
    field_245_X = []
    field_245_X.extend(field_245_0)
    field_245_X.extend(field_245_1)
    field_245_X.extend(field_245_2)
    field_245_X.extend(field_245_3)
    field_245_X.extend(field_245_4)
    field_245_X.extend(field_245_5)



    alt_titles = bfo.fields('246_1', 1)
    edition_statement = bfo.field('250__a', 1)

    out = ""


    if len(main_corporate_authors) > 0: # Why is this here?
        out += " : ".join(main_corporate_authors) + " : "

    for title in titles:
        out += title.get('a')
        if title.has_key('b'):
            out += ' : ' + title['b']
        if title.has_key('s'):
            out += ' : ' + title['s']

    for section in sections:
        if section.has_key('n'):
            out += " " + section['n']
            if section.has_key('p'):
                out += " : " + section['p']

    for inst in field_245_X:
        out += inst.get('a')
        if inst.has_key('b'):
            out += ' : ' + inst['b']
        if inst.has_key('s'):
            out += ' : ' + inst['s']

    for alt_title in alt_titles:
        out += "<br /><b><i>" + alt_title.get('a') + '</i></b>'
        if alt_title.has_key('b'):
            out += ' : ' + alt_title['b']
        if alt_title.has_key('s'):
            out += ' : ' + alt_title['s']

    #Try to display edition statement if other titles were not found
    if out == '' and edition_statement != '':
        out += " ; " + edition_statement


    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(out, bfo.search_pattern,
                                        prefix_tag="<span style='font-weight: bolder'>",
                                        suffix_tag='</style>')


    if force_title_case.lower()=="yes" and (out.upper()==out or re.search('THE ',out)):   #title is allcaps
        out=' '.join([word.capitalize() for word in out.split(' ')])   # should not cap 1 letter words...

    if bfo.field('960__a') == '40':
        out += "<br />"
    return out
Exemplo n.º 19
0
def format_element(bfo, limit, separator='; ',
           extension='[...]',
           print_links="yes",
           print_affiliations='no',
           affiliation_prefix=' (',
           affiliation_suffix=')',
           print_affiliation_first='no',
           interactive="no",
           highlight="no",
           affiliations_separator=" ; ",
           name_last_first="yes",
           collaboration="yes",
           id_links="no",
           markup="html",
           link_extension="no",
           ):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param print_affiliation_first: if 'yes', affiliation is printed before the author
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param affiliations_separator: separates affiliation groups
    @param name_last_first: if yes (default) print last, first  otherwise first last
    @param collaboration: if yes (default) uses collaboration name in place of long author list, if available
    @param id_links: if yes (default = no) prints link based on INSPIRE IDs if available - only used if print_links = yes
    @param markup: html (default) or latex controls small markup differences
    @param link_extension: if 'yes' link the extension to the detailed
    record page

    """
    from urllib import quote
    from cgi import escape
    import re
    from invenio.config import CFG_BASE_URL, CFG_SITE_RECORD, CFG_SITE_URL

    #regex for parsing last and first names and initials
    re_last_first = re.compile('^(?P<last>[^,]+)\s*,\s*(?P<first_names>[^\,]*)(?P<extension>\,?.*)$')
    re_initials = re.compile(r'(?P<initial>\w)(\w+|\.)\s*')
    re_coll = re.compile(r'\s*collaborations?', re.IGNORECASE)

    from invenio.messages import gettext_set_language

    _ = gettext_set_language(bfo.lang)    # load the right message language

    bibrec_id = bfo.control_field("001")
    authors = []
    authors = bfo.fields('100__', repeatable_subfields_p=True)
    authors.extend(bfo.fields('700__', repeatable_subfields_p=True))

    # Keep real num of authorsfix + affiliations_separator.join(author['u']) + \
    nb_authors = len(authors)

    # Limit num of authors, so that we do not process
    # the authors that will not be shown. This can only
    # be done in non-interactive mode, as interactive mode
    # allows to show all of them.
    if limit.isdigit() and nb_authors > int(limit) \
           and interactive != "yes":
        if bfo.field('710g'):   #check for colln note
            authors = authors[:1]
        else:
            authors = authors[:int(limit)]

    # Process authors to add link, affiliation and highlight
    for author in authors:

        if author.has_key('a'):
            author['a'] = author['a'][0] # There should not be
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            #check if we need to reverse last, first
            #we don't try to reverse it if it isn't stored with a comma.
            first_last_match = re_last_first.search(author['a'])
            author['display'] = author['a']

            if name_last_first.lower() == "no":
                if first_last_match:
                    author['display'] = first_last_match.group('first_names') + \
                                        ' ' + \
                                        first_last_match.group('last') + \
                                        first_last_match.group('extension')

            #for latex we do initials only  (asn assume first last)
            if markup == 'latex':
                if first_last_match:
                    first = re_initials.sub('\g<initial>.~', \
                                        first_last_match.group('first_names'))
                    author['display'] = first + \
                                        first_last_match.group('last') + \
                                        first_last_match.group('extension')


            if print_links.lower() == "yes":

                # if there is an ID, search using that.
                id_link = ''
                if id_links == "yes" and author.has_key('i'):
                    author['i'] = author['i'][0]  #possible to have more IDs?
                    id_link = '<a class="authoridlink" href="' + \
                              CFG_BASE_URL + \
                              '/search?' + \
                              'ln=' + bfo.lang + \
                              '&amp;p=100__i' + escape(':' + author['i']) + \
                              '+or+700__i' + escape(':' + author['i']) + \
                              '">' + escape("(ID Search)") + '</a> '


                author['display'] = '<a class="authorlink" target="_blank" ' + \
                                    'href="' + \
                                    CFG_SITE_URL + \
                                    '/author/search?q=' + bibrec_id + ':' + \
                                    quote(author['a']) + \
                                    '&ln=' + bfo.lang + \
                                    '">' + escape(author['display']) + '</a>' + \
                                    id_link

        if print_affiliations == "yes":
            if author.has_key('e'):
                author['e'] = affiliation_prefix + \
                              affiliations_separator.join(author['e']) + \
                              affiliation_suffix



            if author.has_key('u'):
                author['ilink'] = ['%s' % string.lstrip()
                                   for string in author['u']]
                author['u'] = affiliation_prefix + \
                              affiliations_separator.join(author['ilink']) + \
                              affiliation_suffix



#
#  Consolidate repeated affiliations
#

    last = ''
    authors.reverse()
    for author in authors:
        if not author.has_key('u'):
            author['u'] = ''
        #print 'this->'+ author['a']+'\n'
        if last == author['u']:
            author['u'] = ''
        else:
            last = author['u']

    authors.reverse()

    # Flatten author instances
    if print_affiliations == 'yes':
##      100__a (100__e)  700__a (100__e) (100__u)
        if print_affiliation_first.lower() != 'yes':
            authors = [author.get('display', '') + author.get('u', '') \
                       for author in authors]

        else:
            authors = [author.get('u', '') + author.get('display', '')  \
                       for author in authors]


    else:
        authors = [author.get('display', '')
                   for author in authors]

    # link the extension to detailed record
    if link_extension == 'yes' and interactive != 'yes':
        extension = '<a class="authorlink" href="' + \
                    CFG_BASE_URL + '/' + CFG_SITE_RECORD + '∕' + str(bfo.recID) + '">' + \
                    extension + '</a>'

    # Detect Collaborations:
    if collaboration == "yes":
        colls = bfo.fields("710__g")
    else:
        colls = []
    if colls:
        short_coll = False
        colls = [re_coll.sub('', coll) for coll in colls]
        if print_links.lower() == "yes":
            colls = ['<a class="authorlink" href="' + \
                     CFG_BASE_URL + '/search' + \
                     '?p=' + quote(coll) + \
                     '&amp;ln=' + bfo.lang + \
                     '&amp;f=collaboration' + \
                     '">' + escape(coll) + '</a>' for coll in colls]

        coll_display = " and ".join(colls)
        if not coll_display.endswith("aboration"):
            coll_display += " Collaboration"
            if len(colls) > 1:
                coll_display += 's'
        if nb_authors > 1:
            if markup == 'latex':
                coll_display = authors[0] + extension + " [ " + \
                               coll_display + " ]"
            elif interactive == "yes":
                coll_display += " (" + authors[0] + " "
                extension += ")"
            else:  #html
                coll_display += " (" + authors[0] + extension + ")"
        elif nb_authors == 1:
            short_coll = True
            if markup == 'latex':
                coll_display = authors[0] + " [ " + coll_display + " ]"
            else:  #html
                coll_display += " (" + authors[0] + " for the collaboration)"
        elif nb_authors == 0:
            short_coll = True
            if markup == 'latex':
                coll_display = "[ " + coll_display + " ]"



    # Start outputting, depending on options and number of authors
    if colls and (interactive != "yes" or short_coll):
        return coll_display

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:len(authors)]) + \
               extension


    elif interactive == "yes" and  ((colls and not short_coll) or (limit.isdigit() and nb_authors > int(limit))):
        out = '''
        <script>
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = '%(extension)s';
            toggle_authors_visibility();
        }

        </script>
        ''' % {'show_less':_("Hide"),
               'show_more':_("Show all %i authors") % nb_authors,
               'extension':extension}

#        out += '<a name="show_hide" />'
        if colls:
            show = coll_display
            more = separator + separator.join(authors[1:]) + ')'
        else:
            show = separator.join(authors[:int(limit)])
            more = separator.join(authors[int(limit):len(authors)])

        out += show
        out += ' <span id="more" style="">' + more + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a id="link" href="#"' + \
               ' onclick="toggle_authors_visibility()" ' + \
               ' style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script>set_up()</script>'
        return out
    elif nb_authors > 0:
        return separator.join(authors)
Exemplo n.º 20
0
def format_element(bfo, limit, separator=' ; ',
           extension='[...]',
           print_links="yes",
           print_affiliations='no',
           affiliation_prefix=' (',
           affiliation_suffix=')',
           interactive="no",
           highlight="no",
           link_author_pages="no",
           link_mobile_pages="no",
           relator_code_pattern=None):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param link_author_pages: should we link to author pages if print_links in on?
    @param link_mobile_pages: should we link to mobile app pages if print_links in on?
    @param relator_code_pattern: a regular expression to filter authors based on subfield $4 (relator code)
    """
    _ = gettext_set_language(bfo.lang)    # load the right message language

    authors = []
    authors_1 = bfo.fields('100__', repeatable_subfields_p=True)
    authors_2 = bfo.fields('700__', repeatable_subfields_p=True)

    authors.extend(authors_1)
    authors.extend(authors_2)

    # make unique string per key
    for author in authors:
        if 'a' in author:
            author['a'] = author['a'][0]
        if 'u' in author:
            author['u'] = author['u'][0]
        pattern = '%s' + CFG_BIBAUTHORITY_PREFIX_SEP + "("
        for control_no in author.get('0', []):
            if pattern % (CFG_BIBAUTHORITY_TYPE_NAMES["INSTITUTE"]) in control_no:
                author['u0'] = control_no # overwrite if multiples
            elif pattern % (CFG_BIBAUTHORITY_TYPE_NAMES["AUTHOR"]) in control_no:
                author['a0'] = control_no # overwrite if multiples


    if relator_code_pattern:
        p = re.compile(relator_code_pattern)
        authors = filter(lambda x: p.match(x.get('4', '')), authors)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if author.has_key('a'):
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(author['a'],
                                                        bfo.search_pattern)

            if print_links.lower() == "yes":
                if link_author_pages == "yes":
                    author['a'] = '<a rel="author" href="' + CFG_BASE_URL + \
                                  '/author/profile/' + quote(author['a']) + \
                                  '?recid=' +  bibrec_id + \
                                  '&ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'
                elif link_mobile_pages == 'yes':
                    author['a'] = '<a rel="external" href="#page=search' + \
                                  '&amp;f=author&amp;p=' + quote(author['a']) + \
                                  '">' + escape(author['a']) + '</a>'
                else:
                    auth_coll_param = ''
                    if 'a0' in author:
                        recIDs = get_low_level_recIDs_from_control_no(author['a0'])
                        if len(recIDs):
                            auth_coll_param = '&amp;c=' + \
                                              CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME
                    author['a'] = '<a href="' + CFG_BASE_URL + \
                                  '/search?f=author&amp;p=' + quote(author['a']) + \
                                   auth_coll_param + \
                                  '&amp;ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'

        if author.has_key('u'):
            if print_affiliations == "yes":
                if 'u0' in author:
                    recIDs = get_low_level_recIDs_from_control_no(author['u0'])
                    # if there is more than 1 recID, clicking on link and
                    # thus displaying the authority record's page should
                    # contain a warning that there are multiple authority
                    # records with the same control number
                    if len(recIDs):
                        author['u'] = '<a href="' + CFG_BASE_URL + '/' + CFG_SITE_RECORD + '/' + \
                                      str(recIDs[0]) + \
                                      '?ln=' + bfo.lang + \
                                      '">' + author['u'] + '</a>'
                author['u'] = affiliation_prefix + author['u'] + \
                              affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [author.get('a', '') + author.get('u', '')
                   for author in authors]
    else:
        authors = [author.get('a', '')
                   for author in authors]

    if limit.isdigit() and  nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more_%s" style="">' % bibrec_id + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension_%s"></span>' % bibrec_id
        out += ' <small><i><a id="link_%s" href="#" style="color:rgb(204,0,0);"></a></i></small>' % bibrec_id
        out += '''
        <script type="text/javascript">
        $('#link_%(recid)s').click(function(event) {
            event.preventDefault();
            var more = document.getElementById('more_%(recid)s');
            var link = document.getElementById('link_%(recid)s');
            var extension = document.getElementById('extension_%(recid)s');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        });

        function set_up_%(recid)s(){
            var extension = document.getElementById('extension_%(recid)s');
            extension.innerHTML = "%(extension)s";
            $('#link_%(recid)s').click();
        }

        </script>
        ''' % {'show_less':_("Hide"),
             'show_more':_("Show all %i authors") % nb_authors,
             'extension':extension,
             'recid': bibrec_id}
        out += '<script type="text/javascript">set_up_%s()</script>' % bibrec_id

        return out
    elif nb_authors > 0:
        return separator.join(authors)
def format_element(bfo, separator=" ", highlight='no'):
    """
    Prints the titles of a record. Makes a link to detailed record.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    import cgi
    import re
    from invenio.urlutils import create_html_link
    from invenio.messages import gettext_set_language
    from invenio.config import CFG_SITE_URL

    _ = gettext_set_language(bfo.lang)  # load the right message language

    recid = bfo.control_field('001')
    ln = ''

    titles = []

    title = bfo.field('24510a')
    title_remainder = bfo.field('24510b')
    edition_statement = bfo.field('25010a')
    title_tome = bfo.field('24510n')
    title_part = bfo.field('24510p')

    if len(title) == 0:
        title = bfo.field('245__a')
        title_remainder = bfo.field('245__b')
        edition_statement = bfo.field('250__a')
        title_tome = bfo.field('245__n')
        title_part = bfo.field('245__p')

    if len(title) == 0:
        title = bfo.field('24511a')
        title_remainder = bfo.field('24511b')
        edition_statement = bfo.field('25011a')
        title_tome = bfo.field('24511n')
        title_part = bfo.field('24511p')

    if len(title) == 0:
        title = bfo.field('24512a')
        title_remainder = bfo.field('24512b')
        edition_statement = bfo.field('25012a')
        title_tome = bfo.field('24512n')
        title_part = bfo.field('24512p')

    if len(title) == 0:
        title = bfo.field('24513a')
        title_remainder = bfo.field('24513b')
        edition_statement = bfo.field('25013a')
        title_tome = bfo.field('24513n')
        title_part = bfo.field('24513p')

    if len(title) == 0:
        title = bfo.field('24514a')
        title_remainder = bfo.field('24514b')
        edition_statement = bfo.field('25014a')
        title_tome = bfo.field('24514n')
        title_part = bfo.field('24514p')

    if len(title) == 0:
        title = bfo.field('24515a')
        title_remainder = bfo.field('24515b')
        edition_statement = bfo.field('25015a')
        title_tome = bfo.field('24515n')
        title_part = bfo.field('24515p')

    if len(title) == 0:
        title = bfo.field('24516a')
        title_remainder = bfo.field('24516b')
        edition_statement = bfo.field('25016a')
        title_tome = bfo.field('24516n')
        title_part = bfo.field('24516p')

    if len(title) == 0:
        title = bfo.field('24517a')
        title_remainder = bfo.field('24517b')
        edition_statement = bfo.field('25017a')
        title_tome = bfo.field('24517n')
        title_part = bfo.field('24517p')

    if len(title) == 0:
        title = bfo.field('24518a')
        title_remainder = bfo.field('24518b')
        edition_statement = bfo.field('25018a')
        title_tome = bfo.field('24518n')
        title_part = bfo.field('24518p')

    if len(title) == 0:
        title = bfo.field('24519a')
        title_remainder = bfo.field('24519b')
        edition_statement = bfo.field('25019a')
        title_tome = bfo.field('24519n')
        title_part = bfo.field('24519p')

    if len(title) == 0:
        title = bfo.field('24500a')
        title_remainder = bfo.field('24500b')
        edition_statement = bfo.field('25000a')
        title_tome = bfo.field('24500n')
        title_part = bfo.field('24500p')

    if len(title) == 0:
        title = bfo.field('24501a')
        title_remainder = bfo.field('24501b')
        edition_statement = bfo.field('25001a')
        title_tome = bfo.field('24501n')
        title_part = bfo.field('24501p')

    if len(title) == 0:
        title = bfo.field('24502a')
        title_remainder = bfo.field('24502b')
        edition_statement = bfo.field('25002a')
        title_tome = bfo.field('24502n')
        title_part = bfo.field('24502p')

    if len(title) == 0:
        title = bfo.field('24503a')
        title_remainder = bfo.field('24503b')
        edition_statement = bfo.field('25003a')
        title_tome = bfo.field('24503n')
        title_part = bfo.field('24503p')

    if len(title) == 0:
        title = bfo.field('24504a')
        title_remainder = bfo.field('24504b')
        edition_statement = bfo.field('25004a')
        title_tome = bfo.field('24504n')
        title_part = bfo.field('24504p')

    if len(title) == 0:
        title = bfo.field('24505a')
        title_remainder = bfo.field('24505b')
        edition_statement = bfo.field('25005a')
        title_tome = bfo.field('24505n')
        title_part = bfo.field('24505p')

    if len(title) == 0:
        title = bfo.field('24506a')
        title_remainder = bfo.field('24506b')
        edition_statement = bfo.field('25006a')
        title_tome = bfo.field('24506n')
        title_part = bfo.field('24506p')

    if len(title) == 0:
        title = bfo.field('24507a')
        title_remainder = bfo.field('24507b')
        edition_statement = bfo.field('25007a')
        title_tome = bfo.field('24507n')
        title_part = bfo.field('24507p')

    if len(title) == 0:
        title = bfo.field('24508a')
        title_remainder = bfo.field('24508b')
        edition_statement = bfo.field('25008a')
        title_tome = bfo.field('24508n')
        title_part = bfo.field('24508p')

    if len(title) == 0:
        title = bfo.field('24509a')
        title_remainder = bfo.field('24509b')
        edition_statement = bfo.field('25009a')
        title_tome = bfo.field('24509n')
        title_part = bfo.field('24509p')

    if len(title) > 0:
        if title_remainder:
            title += ': ' + title_remainder
            title = title.replace('::', ':')
        if len(title_tome) > 0:
            title += ", " + title_tome
        if len(title_part) > 0:
            title += ": " + title_part
            title = title.replace(':', ':')
        title = re.sub('/$', '', title)
        title = re.sub(':$', '', title)
        titles.append(title)

    title = bfo.field('0248_a')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246__a')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246__b')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246_1a')
    if len(title) > 0:
        titles.append(title)

    if len(titles) > 0:
        #Display 'Conference' title only if other titles were not found
        title = bfo.field('111__a')
        if len(title) > 0:
            titles.append(title)

    #titles = [cgi.escape(x) for x in titles]

    if highlight == 'yes':
        from invenio import bibformat_utils
        titles = [
            bibformat_utils.highlight(x, bfo.search_pattern) for x in titles
        ]

    lang = '?ln=' + bfo.lang
    target = '<a class="detailsTitle" href="%s/record/%s%s">' % (CFG_SITE_URL,
                                                                 recid, lang)

    # make a detailed record link
    if len(edition_statement) > 0:
        return target + separator.join(
            titles) + "; " + edition_statement + "</a>"
    else:
        return target + separator.join(titles) + "</a>"
Exemplo n.º 22
0
def format_element(bfo, separator=" ", highlight='no', latex_to_html='no', link_to_fulltext='no', punctuation = ''):
    """
    Prints the titles of a record.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    @param latex_to_html: if 'yes', interpret as LaTeX title
    @param link_to_fulltext: if 'yes', link title to fulltext if available.
    @param punctuation: add this char if the title don't already end with one
    """
    titles = []

    title = bfo.field('245__a', escape=2)
    title_remainder = bfo.field('245__b', escape=2)
    edition_statement = bfo.field('250__a', escape=2)
    title_tome = bfo.field('245__n', escape=2)
    title_part = bfo.field('245__p', escape=2)
    
    #start with standard number if given
    standard_number = bfo.field('740__a', escape=2)
    
    if len(standard_number) > 0:
        standard_number += ' - '
        titles.append(standard_number)

    if len(title) > 0:
        if title_remainder:
            title += ': ' + title_remainder
        if len(title_tome) > 0:
            title += ", " + title_tome
        if len(title_part) > 0:
            title += ": " + title_part
        titles.append( title )

    title = bfo.field('246__a', escape=2)
    if len(title) > 0:
        titles.append( title )

    title = bfo.field('246__b', escape=2)
    if len(title) > 0:
        titles.append( title )

    title = bfo.field('246_1a', escape=2)
    if len(title) > 0:
        titles.append( title )

    if highlight == 'yes':
        titles = [bibformat_utils.highlight(x, bfo.search_pattern) for x in titles]
    
    if len(edition_statement) > 0:
        out = separator.join(titles) + "; " + edition_statement
    else:
        out = separator.join(titles)
    
    if latex_to_html == 'yes':
        out = bibformat_utils.latex_to_html(out)
    
    if link_to_fulltext == 'yes':
        out = add_link_to_fulltext(bfo, out) 
        
    # add a , at the  end if not already
    if out and punctuation:
        if out[-1] not in [',', '.', '!', '?', ';']:
            out += punctuation
    
    return out
Exemplo n.º 23
0
def format_element(
    bfo,
    limit,
    separator=" ; ",
    extension="[...]",
    print_links="yes",
    print_affiliations="no",
    affiliation_prefix=" (",
    affiliation_suffix=")",
    interactive="no",
    highlight="no",
    link_author_pages="no",
    link_mobile_pages="no",
    relator_code_pattern=None,
):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param link_author_pages: should we link to author pages if print_links in on?
    @param link_mobile_pages: should we link to mobile app pages if print_links in on?
    @param relator_code_pattern: a regular expression to filter authors based on subfield $4 (relator code)
    """
    _ = gettext_set_language(bfo.lang)  # load the right message language

    authors = []
    authors_1 = bfo.fields("100__")
    authors_2 = bfo.fields("700__")

    authors.extend(authors_1)
    authors.extend(authors_2)

    if relator_code_pattern:
        p = re.compile(relator_code_pattern)
        authors = filter(lambda x: p.match(x.get("4", "")), authors)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if author.has_key("a"):
            if highlight == "yes":
                from invenio import bibformat_utils

                author["a"] = bibformat_utils.highlight(author["a"], bfo.search_pattern)

            if print_links.lower() == "yes":
                if link_author_pages == "yes":
                    author["a"] = (
                        '<a rel="author" href="'
                        + CFG_SITE_URL
                        + "/author/"
                        + quote(author["a"])
                        + "?recid="
                        + bibrec_id
                        + "&ln="
                        + bfo.lang
                        + '">'
                        + escape(author["a"])
                        + "</a>"
                    )
                elif link_mobile_pages == "yes":
                    author["a"] = (
                        '<a rel="external" href="#page=search'
                        + "&amp;f=author&amp;p="
                        + quote(author["a"])
                        + '">'
                        + escape(author["a"])
                        + "</a>"
                    )
                else:
                    author["a"] = (
                        '<a href="'
                        + CFG_SITE_URL
                        + "/search?f=author&amp;p="
                        + quote(author["a"])
                        + "&amp;ln="
                        + bfo.lang
                        + '">'
                        + escape(author["a"])
                        + "</a>"
                    )

        if author.has_key("u"):
            if print_affiliations == "yes":
                author["u"] = affiliation_prefix + author["u"] + affiliation_suffix

    # Flatten author instances
    if print_affiliations == "yes":
        authors = [author.get("a", "") + author.get("u", "") for author in authors]
    else:
        authors = [author.get("a", "") for author in authors]

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[: int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '<a name="show_hide" />'
        out += separator.join(authors[: int(limit)])
        out += (
            '<span id="more_%s" style="">' % bibrec_id + separator + separator.join(authors[int(limit) :]) + "</span>"
        )
        out += ' <span id="extension_%s"></span>' % bibrec_id
        out += ' <small><i><a id="link_%s" href="#" style="color:rgb(204,0,0);"></a></i></small>' % bibrec_id
        out += """
        <script type="text/javascript">
        $('#link_%(recid)s').click(function(event) {
            event.preventDefault();
            var more = document.getElementById('more_%(recid)s');
            var link = document.getElementById('link_%(recid)s');
            var extension = document.getElementById('extension_%(recid)s');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        });

        function set_up_%(recid)s(){
            var extension = document.getElementById('extension_%(recid)s');
            extension.innerHTML = "%(extension)s";
            $('#link_%(recid)s').click();
        }

        </script>
        """ % {
            "show_less": _("Hide"),
            "show_more": _("Show all %i authors") % nb_authors,
            "extension": extension,
            "recid": bibrec_id,
        }
        out += '<script type="text/javascript">set_up_%s()</script>' % bibrec_id

        return out
    elif nb_authors > 0:
        return separator.join(authors)
Exemplo n.º 24
0
def format_element(
    bfo,
    limit,
    separator='; ',
    extension='[...]',
    print_links="yes",
    print_affiliations='no',
    affiliation_prefix=' (',
    affiliation_suffix=')',
    print_affiliation_first='no',
    interactive="no",
    highlight="no",
    affiliations_separator=" ; ",
    name_last_first="yes",
    collaboration="yes",
    id_links="no",
    markup="html",
    link_extension="no",
):
    """
    Prints the list of authors of a record.

    @param limit the maximum number of authors to display
    @param separator the separator between authors.
    @param extension a text printed if more authors than 'limit' exist
    @param print_links if yes, prints the authors as HTML link to their
           publications
    @param print_affiliations if yes, make each author name followed by
           its affiliation
    @param affiliation_prefix prefix printed before each affiliation
    @param affiliation_suffix suffix printed after each affiliation
    @param print_affiliation_first if 'yes', affiliation is printed before
           the author
    @param interactive if yes, enable user to show/hide authors when there
           are too many (html + javascript)
    @param highlight highlights authors corresponding to search query if set
           to 'yes'
    @param affiliations_separator separates affiliation groups
    @param name_last_first if yes (default) print last, first  otherwise
           print first last
    @param collaboration if yes (default) uses collaboration name in place
           of long author list, if available
    @param id_links if yes (default = no) prints link based on INSPIRE IDs
           if available - only used if print_links = yes
    @param markup html (default) or latex or bibtex controls small markup
           differences
    @param link_extension if 'yes' link the extension to the detailed
           record page

    """
    from urllib import quote
    from cgi import escape
    import re
    from invenio.messages import gettext_set_language
    from invenio.config import CFG_SITE_RECORD

    try:
        from invenio.config import CFG_BASE_URL
    except ImportError:
        from invenio.config import CFG_SITE_URL
        CFG_BASE_URL = CFG_SITE_URL

    _ = gettext_set_language(bfo.lang)  # load the right message language

    # regex for parsing last and first names and initials
    re_last_first = re.compile(
        r'^(?P<last>[^,]+)\s*,\s*(?P<first_names>[^\,]*)(?P<extension>\,?.*)$')
    re_initials = re.compile(r'(?P<initial>\w)([\w`\']+)?.?\s*', re.UNICODE)
    re_tildehyph = re.compile(
        ur'(?<=\.)~(?P<hyphen>[\u002D\u00AD\u2010-\u2014-])(?=\w)', re.UNICODE)
    re_coll = re.compile(r'\s*collaborations?', re.IGNORECASE)

    bibrec_id = bfo.control_field("001")
    authors = []
    lastauthor = ''
    only_corporate_author = False
    authors = bfo.fields('100__', repeatable_subfields_p=True)
    authors.extend(bfo.fields('700__', repeatable_subfields_p=True))

    # If there are no authors check for corporate author in 110__a field
    if len(authors) == 0:
        authors = bfo.fields('110__', repeatable_subfields_p=True)
        if len(authors) > 0:
            only_corporate_author = True
        # For corporate authors we don't want to reverse names order
        name_last_first = 'yes'
        # And we don't want to create links
        print_links = 'no'

    # authors is a list of dictionaries, count only those with names
    # e.g. naive count of this
    # [{'a': ['Toge, Nobu']},
    #  {'u': ['Kek, High Energy Accelerator Research Organization']},
    #  {'u': ['1-1 Oho, Tsukuba-Shi, Ibaraki-Ken, 305 Japan']}]
    # would be 3, but there is only 1 author
    nb_authors = len([au for au in authors if 'a' in au])

    if markup == 'bibtex':
        # skip editors
        authors = [
            au for au in authors
            if 'a' in au and not ('e' in au and 'ed.' in au['e'])
        ]
        nb_authors = len(authors)

    # Limit num of authors, so that we do not process
    # the authors that will not be shown. This can only
    # be done in non-interactive mode, as interactive mode
    # allows to show all of them.
    if limit.isdigit() and nb_authors > int(limit) \
            and interactive != "yes":
        authors = authors[:1]

    # Process authors to add link, affiliation and highlight
    for author in authors:
        if 'a' in author:
            # There should not be repeatable subfields here
            author['a'] = author['a'][0]
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(
                    author['a'], bfo.search_pattern)

            # check if we need to reverse last, first
            # we don't try to reverse it if it isn't stored with a comma.
            first_last_match = re_last_first.search(author['a'])
            author['display'] = author['a']

            if name_last_first.lower() == "no":
                if first_last_match:
                    author['display'] = "%s %s%s" % (
                        first_last_match.group('first_names'),
                        first_last_match.group('last'),
                        first_last_match.group('extension'),
                    )

            # for latex we do initials only (and assume first last)
            if markup == 'latex':
                if first_last_match:
                    first = re_initials.sub(
                        r'\g<initial>.~',
                        unicode(first_last_match.group('first_names'), 'utf8'))
                    first = re_tildehyph.sub(r'\g<hyphen>', first)
                    author['display'] = first + \
                        first_last_match.group('last') + \
                        first_last_match.group('extension')

            # custom name handling for bibtex
            if markup == 'bibtex':
                if first_last_match:
                    junior = first_last_match.group('extension')
                    if re.search(r'\b([JS]r\.)?$', junior) or \
                            re.search('([IV]{2,})$', junior):
                        author['display'] = "%s%s, %s" % (
                            first_last_match.group('last'),
                            junior,
                            first_last_match.group('first_names'),
                        )
                    else:
                        author['display'] = "%s, %s%s" % (
                            first_last_match.group('last'),
                            first_last_match.group('first_names'),
                            junior,
                        )

                    # avoid trailing comma for single name author
                    author['display'] = author['display'].rstrip(', ')

                    # multi-letter initial (in particular Russian Yu., Ya. ...)
                    # http://usefulenglish.ru/vocabulary/russian-names-in-english-en
                    author['display'] = re.sub(r'\bY([aeou])\.',
                                               r'{\\relax Y\1}.',
                                               author['display'])

            if print_links.lower() == "yes":
                # if there is an ID, search using that.
                id_link = ''
                if id_links == "yes" and 'i' in author:
                    author['i'] = author['i'][0]  # possible to have more IDs?
                    id_link = '<a class="authoridlink" href="' + \
                              CFG_BASE_URL + \
                              '/search?ln=' + bfo.lang + \
                              '&amp;p=100__i:' + escape(author['i']) + \
                              '+or+700__i:' + escape(author['i']) +\
                              '">' + escape("(ID Search)") + '</a> '

                author['display'] = '<a class="authorlink" href="' + \
                                    CFG_BASE_URL + \
                                    '/author/profile/' + quote(author['a']) + \
                                    '?recid=' + bibrec_id + \
                                    '&amp;ln=' + bfo.lang + \
                                    '">' + escape(author['display'])+'</a>' + \
                                    id_link

        if print_affiliations == "yes":
            if 'e' in author:
                author['e'] = affiliation_prefix + \
                    affiliations_separator.join(author['e']) + \
                    affiliation_suffix

            if 'u' in author:
                author['ilink'] = [
                    '<a class="afflink" href="' + CFG_BASE_URL +
                    '/search?cc=Institutions&amp;p=institution:' +
                    quote('"' + string + '"') + '&amp;ln=' + bfo.lang + '">' +
                    string.lstrip() + '</a>' for string in author['u']
                ]
                author['u'] = affiliation_prefix + \
                    affiliations_separator.join(author['ilink']) + \
                    affiliation_suffix

#
#  Consolidate repeated affiliations
#

    last = ''
    authors.reverse()
    for author in authors:
        if 'u' not in author:
            author['u'] = ''
        #print 'this->'+ author['a']+'\n'
        if last == author['u']:
            author['u'] = ''
        else:
            last = author['u']

    authors.reverse()

    # Flatten author instances
    if print_affiliations == 'yes':
        # 100__a (100__e)  700__a (100__e) (100__u)
        if print_affiliation_first.lower() != 'yes':
            authors = [
                author.get('display', '') + author.get('e', '') +
                author.get('u', '') for author in authors
            ]
        else:
            authors = [
                author.get('u', '') + author.get('display', '')
                for author in authors
            ]
    else:
        authors = [
            author.get('display', '') for author in authors
            if 'display' in author
        ]

    # link the extension to detailed record
    if link_extension == 'yes' and interactive != 'yes':
        extension = '<a class="authorlink" href="' +  \
            CFG_BASE_URL + '/' + CFG_SITE_RECORD + '/' + str(bfo.recID) \
            + '">' + extension + '</a>'

    # Detect Collaborations:
    if collaboration == "yes":
        colls = []
        for coll in bfo.fields("710__g"):
            if coll not in colls:
                colls.append(coll)
    else:
        colls = []

    if colls:
        short_coll = False
        colls = [re_coll.sub('', coll) for coll in colls]
        if print_links.lower() == "yes":
            colls = [
                '<a class="authorlink" href="' + CFG_BASE_URL + '/search' +
                '?p=collaboration:' + quote("'" + coll + "'") + '&amp;ln=' +
                bfo.lang + '">' + escape(coll) + '</a>' for coll in colls
            ]

        noncollabterms = ('group', 'task force', 'consortium', 'team')
        noncolls = []
        truecolls = []
        for coll in colls:
            lcoll = coll.lower()
            noncoll = False
            for term in noncollabterms:
                if term in lcoll:
                    noncolls.append(coll)
                    noncoll = True
                    break
            if noncoll is False:
                truecolls.append(coll)

        coll_display = " and ".join(truecolls)
        if truecolls and not coll_display.endswith("aboration"):
            coll_display += " Collaboration"
            if len(truecolls) > 1:
                coll_display += 's'
        if truecolls and noncolls:
            coll_display += ' and '
        if noncolls:
            coll_display += ' and '.join(noncolls)
        if nb_authors > 1:
            if markup in ('latex', 'bibtex'):
                coll_display = authors[0] + extension + " [" + \
                    coll_display + "]"
            elif interactive == "yes":
                coll_display += " (" + authors[0] + " "
                extension += ")"
            else:  # html
                coll_display += " (" + authors[0] + extension + ")"
        elif nb_authors == 1:
            short_coll = True
            if markup in ('latex', 'bibtex'):
                coll_display = authors[0] + " [" + coll_display + "]"
            else:  # html
                if not only_corporate_author:
                    coll_display += " (" + authors[0] + \
                                    " for the collaboration)"
        elif nb_authors == 0:
            short_coll = True
            if markup in ('latex', 'bibtex'):
                coll_display = "[" + coll_display + "]"

    # Start outputting, depending on options and number of authors
    if colls and (interactive != "yes" or short_coll):
        return coll_display

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + lastauthor + \
            extension

    elif interactive == "yes" and \
            ((colls and not short_coll) or
             (limit.isdigit() and nb_authors > int(limit))):
        out = '''
        <script>
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = '%(extension)s';
            toggle_authors_visibility();
        }

        </script>
        ''' % {
            'show_less': _("Hide"),
            'show_more': _("Show all %i authors") % nb_authors,
            'extension': extension
        }

        #        out += '<a name="show_hide" />'
        if colls:
            show = coll_display
            more = separator + separator.join(authors[1:]) + ')'
        else:
            show = separator.join(authors[:int(limit)])
            more = separator + separator.join(authors[int(limit):len(authors)])

        out += show
        out += '<span id="more" style="">' + more + '</span>'
        out += '<span id="extension"></span>'
        out += '&nbsp;&nbsp;<small><i><a id="link" href="#"' + \
               ' style="color:green;background:white;" onclick="toggle_authors_visibility()" ' + \
               ' style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script>set_up()</script>'
        return out
    elif nb_authors > 0:
        if markup in ('latex', 'bibtex'):
            if nb_authors > 1:
                lastauthor = ' and ' + authors.pop()
        return separator.join(authors) + lastauthor
Exemplo n.º 25
0
def format_element(bfo,
                   limit,
                   separator=', ',
                   extension='[...]',
                   print_links="yes",
                   print_affiliations='no',
                   affiliation_prefix=' (',
                   affiliation_suffix=')',
                   interactive="no",
                   highlight="no",
                   link_author_pages="no"):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    """
    from invenio.messages import gettext_set_language

    _ = gettext_set_language(bfo.lang)  # load the right message language

    authors = []
    authors_2 = bfo.fields('65017')

    authors.extend(authors_2)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if author.has_key('a'):
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(
                    author['a'], bfo.search_pattern)

        if author.has_key('a'):
            if print_affiliations == "yes":
                author['a'] = affiliation_prefix + author['a'] + \
                              affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [
            author.get('a', '') + author.get('a', '') for author in authors
        ]
    else:
        authors = [author.get('a', '') for author in authors]

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '''
        <script type="text/javascript">
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = "%(extension)s";
            toggle_authors_visibility();
        }

        </script>
        ''' % {
            'show_less': _("Hide"),
            'show_more': _("Show all %i authors") % nb_authors,
            'extension': extension
        }

        out += '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more" style="">' + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a id="link" href="#" onclick="toggle_authors_visibility()" style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script type="text/javascript">set_up()</script>'
        return out
    elif nb_authors > 0:
        return separator.join(authors)
Exemplo n.º 26
0
def format_element(bfo,
                   limit,
                   separator=' ; ',
                   extension='[...]',
                   print_links="yes",
                   print_affiliations='no',
                   affiliation_prefix=' (',
                   affiliation_suffix=')',
                   interactive="no",
                   highlight="no",
                   link_author_pages="no",
                   link_mobile_pages="no",
                   relator_code_pattern=None,
                   multiple_affiliations="no"):
    """
    Prints the list of authors of a record.

    @param limit: the maximum number of authors to display
    @param separator: the separator between authors.
    @param extension: a text printed if more authors than 'limit' exist
    @param print_links: if yes, prints the authors as HTML link to their publications
    @param print_affiliations: if yes, make each author name followed by its affiliation
    @param affiliation_prefix: prefix printed before each affiliation
    @param affiliation_suffix: suffix printed after each affiliation
    @param interactive: if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight: highlights authors corresponding to search query if set to 'yes'
    @param link_author_pages: should we link to author pages if print_links in on?
    @param link_mobile_pages: should we link to mobile app pages if print_links in on?
    @param relator_code_pattern: a regular expression to filter authors based on subfield $4 (relator code)
    @param multiple_affiliations: whether all affiliations should be displayed
    """
    _ = gettext_set_language(bfo.lang)  # load the right message language

    authors = []
    authors_1 = bfo.fields('100__', repeatable_subfields_p=True)
    authors_2 = bfo.fields('700__', repeatable_subfields_p=True)

    authors.extend(authors_1)
    authors.extend(authors_2)

    # make unique string per key
    for author in authors:
        if 'a' in author:
            author['a'] = author['a'][0]
        if 'u' in author and multiple_affiliations == 'no':
            author['u'] = author['u'][0]
        if 'v' in author and multiple_affiliations == 'no':
            author['v'] = author['v'][0]
        pattern = '%s' + CFG_BIBAUTHORITY_PREFIX_SEP + "("
        for control_no in author.get('0', []):
            if pattern % (
                    CFG_BIBAUTHORITY_TYPE_NAMES["INSTITUTE"]) in control_no:
                author['u0'] = control_no  # overwrite if multiples
            elif pattern % (
                    CFG_BIBAUTHORITY_TYPE_NAMES["AUTHOR"]) in control_no:
                author['a0'] = control_no  # overwrite if multiples

    if relator_code_pattern:
        p = re.compile(relator_code_pattern)
        authors = filter(lambda x: p.match(x.get('4', '')), authors)

    nb_authors = len(authors)

    bibrec_id = bfo.control_field("001")

    # Process authors to add link, highlight and format affiliation
    for author in authors:

        if author.has_key('a'):
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(
                    author['a'], bfo.search_pattern)

            if print_links.lower() == "yes":
                if link_author_pages == "yes":
                    author['a'] = '<a rel="author" href="' + CFG_BASE_URL + \
                                  '/author/profile/' + quote(author['a']) + \
                                  '?recid=' +  bibrec_id + \
                                  '&ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'
                elif link_mobile_pages == 'yes':
                    author['a'] = '<a rel="external" href="#page=search' + \
                                  '&amp;f=author&amp;p=' + quote(author['a']) + \
                                  '">' + escape(author['a']) + '</a>'
                else:
                    auth_coll_param = ''
                    if 'a0' in author:
                        recIDs = get_low_level_recIDs_from_control_no(
                            author['a0'])
                        if len(recIDs):
                            auth_coll_param = '&amp;c=' + \
                                              CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME
                    author['a'] = '<a href="' + CFG_BASE_URL + \
                                  '/search?f=author&amp;p=' + quote(author['a']) + \
                                   auth_coll_param + \
                                  '&amp;ln=' + bfo.lang + \
                                  '">' + escape(author['a']) + '</a>'

        if author.has_key('u') or author.has_key('v'):
            if print_affiliations == "yes":
                if 'u0' in author:
                    recIDs = get_low_level_recIDs_from_control_no(author['u0'])
                    # if there is more than 1 recID, clicking on link and
                    # thus displaying the authority record's page should
                    # contain a warning that there are multiple authority
                    # records with the same control number
                    if isinstance(author['u'], (list, tuple)):
                        author['u'] = author['u'][0]
                    if len(recIDs):
                        author['u'] = '<a href="' + CFG_BASE_URL + '/' + CFG_SITE_RECORD + '/' + \
                                      str(recIDs[0]) + \
                                      '?ln=' + bfo.lang + \
                                      '">' + author['u'] + '</a>'
                if not 'u' in author and 'v' in author:
                    author['u'] = author['v']
                if isinstance(author['u'], (list, tuple)):
                    author['u'] = ' '.join([affiliation_prefix + aff + \
                              affiliation_suffix for aff in author['u']])
                else:
                    author['u'] = affiliation_prefix + author['u'] + \
                              affiliation_suffix

    # Flatten author instances
    if print_affiliations == 'yes':
        authors = [
            author.get('a', '') + author.get('u', '') for author in authors
        ]
    else:
        authors = [author.get('a', '') for author in authors]

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        return separator.join(authors[:int(limit)]) + extension

    elif limit.isdigit() and nb_authors > int(limit) and interactive == "yes":
        out = '<a name="show_hide" />'
        out += separator.join(authors[:int(limit)])
        out += '<span id="more_%s" style="">' % bibrec_id + separator + \
               separator.join(authors[int(limit):]) + '</span>'
        out += ' <span id="extension_%s"></span>' % bibrec_id
        out += ' <small><i><a id="link_%s" href="#" style="color:rgb(204,0,0);"></a></i></small>' % bibrec_id
        out += '''
        <script type="text/javascript">
        $('#link_%(recid)s').click(function(event) {
            event.preventDefault();
            var more = document.getElementById('more_%(recid)s');
            var link = document.getElementById('link_%(recid)s');
            var extension = document.getElementById('extension_%(recid)s');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        });

        function set_up_%(recid)s(){
            var extension = document.getElementById('extension_%(recid)s');
            extension.innerHTML = "%(extension)s";
            $('#link_%(recid)s').click();
        }

        </script>
        ''' % {
            'show_less': _("Hide"),
            'show_more': _("Show all %i authors") % nb_authors,
            'extension': extension,
            'recid': bibrec_id
        }
        out += '<script type="text/javascript">set_up_%s()</script>' % bibrec_id

        return out
    elif nb_authors > 0:
        return separator.join(authors)
Exemplo n.º 27
0
def format_element(
    bfo,
    limit,
    separator='; ',
    extension='[...]',
    print_links="yes",
    print_affiliations='no',
    affiliation_prefix=' (',
    affiliation_suffix=')',
    print_affiliation_first='no',
    interactive="no",
    highlight="no",
    affiliations_separator=" ; ",
    name_last_first="yes",
    collaboration="yes",
    id_links="no",
    markup="html",
    link_extension="no",
):
    """
    Prints the list of authors of a record.

    @param limit the maximum number of authors to display
    @param separator the separator between authors.
    @param extension a text printed if more authors than 'limit' exist
    @param print_links if yes, prints the authors as HTML link to their publications
    @param print_affiliations if yes, make each author name followed by its affiliation
    @param affiliation_prefix prefix printed before each affiliation
    @param affiliation_suffix suffix printed after each affiliation
    @param print_affiliation_first if 'yes', affiliation is printed before the author
    @param interactive if yes, enable user to show/hide authors when there are too many (html + javascript)
    @param highlight highlights authors corresponding to search query if set to 'yes'
    @param affiliations_separator separates affiliation groups
    @param name_last_first if yes (default) print last, first  otherwise first last
    @param collaboration if yes (default) uses collaboration name in place of long author list, if available
    @param id_links if yes (default = no) prints link based on INSPIRE IDs if available - only used if print_links = yes
    @param markup html (default) or latex controls small markup differences
    @param link_extension if 'yes' link the extension to the detailed
    record page

    """
    from urllib import quote
    from cgi import escape
    import re
    from invenio.messages import gettext_set_language
    from invenio.config import CFG_SITE_URL
    from invenio.bibformat_elements.bfe_server_info import format_element as bfe_server

    _ = gettext_set_language(bfo.lang)  # load the right message language

    #regex for parsing last and first names and initials
    re_last_first = re.compile(
        '^(?P<last>[^,]+)\s*,\s*(?P<first_names>[^\,]*)(?P<extension>\,?.*)$')
    re_initials = re.compile(r'(?P<initial>\w)(\w+|\.)\s*')
    re_coll = re.compile(r'\s*collaborations?', re.IGNORECASE)

    bibrec_id = bfo.control_field("001")
    authors = []
    lastauthor = ''
    authors = bfo.fields('100__', repeatable_subfields_p=True)
    authors.extend(bfo.fields('700__', repeatable_subfields_p=True))

    # Keep real num of authors. fix + affiliations_separator.join(author['u']) + \
    nb_authors = len(authors)

    # Limit num of authors, so that we do not process
    # the authors that will not be shown. This can only
    # be done in non-interactive mode, as interactive mode
    # allows to show all of them.
    if limit.isdigit() and nb_authors > int(limit) \
           and interactive != "yes":
        if bfo.field('710g'):  #check for colln note
            authors = authors[:1]
        else:

            authors = authors[:int(limit)]

    # Process authors to add link, affiliation and highlight
    for author in authors:

        if author.has_key('a'):
            author['a'] = author['a'][0]  # There should not be
            # repeatable subfields here.
            if highlight == 'yes':
                from invenio import bibformat_utils
                author['a'] = bibformat_utils.highlight(
                    author['a'], bfo.search_pattern)

            #check if we need to reverse last, first
            #we don't try to reverse it if it isn't stored with a comma.
            first_last_match = re_last_first.search(author['a'])
            author['display'] = author['a']

            if name_last_first.lower() == "no":
                if first_last_match:
                    author['display'] = first_last_match.group('first_names') + \
                                        ' ' + \
                                        first_last_match.group('last') + \
                                        first_last_match.group('extension')

            #for latex we do initials only  (asn assume first last)
            if markup == 'latex':
                if first_last_match:
                    first = re_initials.sub('\g<initial>.~', \
                                        first_last_match.group('first_names'))
                    author['display'] = first  + \
                                        first_last_match.group('last') + \
                                        first_last_match.group('extension')

            if print_links.lower() == "yes":

                # if there is an ID, search using that.
                id_link = ''
                if id_links == "yes" and author.has_key('i'):
                    author['i'] = author['i'][0]  #possible to have more IDs?
                    id_link = '<a class="authoridlink" href="' + \
                              CFG_SITE_URL + \
                              '/search?' + \
                              'ln='+ bfo.lang + \
                              '&amp;p=100__i' + escape(':' + author['i']) + \
                              '+or+700__i' + escape(':' + author['i']) +\
                              '">'+escape("(ID Search)") + '</a> '


                author['display'] = '<a class="authorlink" href="' + \
                                    CFG_SITE_URL + \
                                    '/author/'+ quote(author['a']) + \
                                    '?recid=' + bibrec_id + \
                                    '&amp;ln='+ bfo.lang + \
                                    '">' + escape(author['display'])+'</a>' + \
                                    id_link

        if print_affiliations == "yes":
            if author.has_key('e'):
                author['e'] = affiliation_prefix + \
                              affiliations_separator.join(author['e']) + \
                              affiliation_suffix

            if author.has_key('u'):
                author['ilink'] = ['<a class="afflink" href="' + \
                                   CFG_SITE_URL + '/search?cc=Institutions&amp;p=institution:'+ \
                                   quote('"' + string + '"') + \
                                   '&amp;ln=' + bfo.lang + \
                                   '">' + \
                                   string.lstrip() + \
                                   '</a>' for string in author['u']]
                author['u'] = affiliation_prefix + \
                              affiliations_separator.join(author['ilink']) + \
                              affiliation_suffix

#
#  Consolidate repeated affiliations
#

    last = ''
    authors.reverse()
    for author in authors:
        if not author.has_key('u'):
            author['u'] = ''
        #print 'this->'+ author['a']+'\n'
        if last == author['u']:
            author['u'] = ''
        else:
            last = author['u']

    authors.reverse()

    # Flatten author instances
    if print_affiliations == 'yes':
        ##      100__a (100__e)  700__a (100__e) (100__u)
        if print_affiliation_first.lower() != 'yes':
            authors = [author.get('display', '') + author.get('u', '') \
                       for author in authors]

        else:
            authors = [author.get('u', '') + author.get('display', '')  \
                       for author in authors]

    else:
        authors = [author.get('display', '') for author in authors]

    # link the extension to detailed record
    if link_extension == 'yes' and interactive != 'yes':
        extension = '<a class="authorlink" href="' +  \
                    bfe_server(bfo, var="recurl")+ '">' + \
                    extension + '</a>'

    # Detect Collaborations:
    if collaboration == "yes":
        colls = []
        for coll in bfo.fields("710__g"):
            if coll not in colls:
                colls.append(coll)
    else:
        colls = []
    if colls:
        short_coll = False
        colls = [re_coll.sub('', coll) for coll in colls]
        if print_links.lower() == "yes":
            colls = ['<a class="authorlink" href="' + \
                     bfe_server(bfo,var="searchurl") + \
                     '?p=collaboration:' + quote("'" + coll + "'") + \
                     '&amp;ln='+ bfo.lang + \
                     '">'+escape(coll)+'</a>' for coll in colls]

        coll_display = " and ".join(colls)
        if not coll_display.endswith("aboration"):
            coll_display += " Collaboration"
            if len(colls) > 1:
                coll_display += 's'
        if nb_authors > 1:
            if markup == 'latex':
                coll_display =  authors[0] + extension + "  [" + \
                               coll_display + "]"
            elif interactive == "yes":
                coll_display += " (" + authors[0] + " "
                extension += ")"
            else:  #html
                coll_display += " (" + authors[0] + extension + ")"
        elif nb_authors == 1:
            short_coll = True
            if markup == 'latex':
                coll_display = authors[0] + " [" + coll_display + "]"
            else:  #html
                coll_display += " (" + authors[0] + " for the collaboration)"
        elif nb_authors == 0:
            short_coll = True
            if markup == 'latex':
                coll_display = "[" + coll_display + "]"

    # Start outputting, depending on options and number of authors
    if colls and (interactive != "yes" or short_coll):
        return coll_display

    if limit.isdigit() and nb_authors > int(limit) and interactive != "yes":
        if markup == 'latex':
            lastauthor = authors.pop()
            lastauthor = ' and ' + lastauthor
            limit = int(limit) - 1

        return separator.join(authors[:int(limit)]) + lastauthor + \
               extension

    elif interactive == "yes" and (
        (colls and not short_coll) or
        (limit.isdigit() and nb_authors > int(limit))):
        out = '''
        <script>
        function toggle_authors_visibility(){
            var more = document.getElementById('more');
            var link = document.getElementById('link');
            var extension = document.getElementById('extension');
            if (more.style.display=='none'){
                more.style.display = '';
                extension.style.display = 'none';
                link.innerHTML = "%(show_less)s"
            } else {
                more.style.display = 'none';
                extension.style.display = '';
                link.innerHTML = "%(show_more)s"
            }
            link.style.color = "rgb(204,0,0);"
        }

        function set_up(){
            var extension = document.getElementById('extension');
            extension.innerHTML = '%(extension)s';
            toggle_authors_visibility();
        }

        </script>
        ''' % {
            'show_less': _("Hide"),
            'show_more': _("Show all %i authors") % nb_authors,
            'extension': extension
        }

        #        out += '<a name="show_hide" />'
        if colls:
            show = coll_display
            more = separator + separator.join(authors[1:]) + ')'
        else:
            show = separator.join(authors[:int(limit)])
            more = separator.join(authors[int(limit):len(authors)])

        out += show
        out += ' <span id="more" style="">' + more + '</span>'
        out += ' <span id="extension"></span>'
        out += ' <small><i><a id="link" href="#"' + \
               ' style="color:green;background:white;" onclick="toggle_authors_visibility()" ' + \
               ' style="color:rgb(204,0,0);"></a></i></small>'
        out += '<script>set_up()</script>'
        return out
    elif nb_authors > 0:
        if markup == 'latex':
            if nb_authors > 1:
                lastauthor = authors.pop()
                lastauthor = ' and ' + lastauthor
        return separator.join(authors) + lastauthor
Exemplo n.º 28
0
def format_element(bfo, highlight="no", link_title="yes"):
    """
    Prints a short title, suitable for brief format.

    @param highlight highlights the words corresponding to search query if set to 'yes'
    @param link_title if 'yes', link to detailed record.
    """

    main_corporate_authors = bfo.fields('931__a', 1)
    titles = bfo.fields('245__', 1)
    sections = bfo.fields('246__', 1)
    field_245_0 = bfo.fields('245_0', 1)
    field_245_1 = bfo.fields('245_1', 1)
    field_245_2 = bfo.fields('245_2', 1)
    field_245_3 = bfo.fields('245_3', 1)
    field_245_4 = bfo.fields('245_4', 1)
    field_245_5 = bfo.fields('245_5', 1)
    field_245_X = []
    field_245_X.extend(field_245_0)
    field_245_X.extend(field_245_1)
    field_245_X.extend(field_245_2)
    field_245_X.extend(field_245_3)
    field_245_X.extend(field_245_4)
    field_245_X.extend(field_245_5)
    alt_titles = bfo.fields('246_1', 1)
    edition_statement = bfo.field('250__a', 1)

    out = ""

    if len(main_corporate_authors) > 0:  # Why is this here?
        out += " : ".join(main_corporate_authors) + " : "

    for title in titles:
        out += title.get('a', '')
        if title.has_key('b'):
            out += ' : ' + title['b']
        if title.has_key('s'):
            out += ' : ' + title['s']

    for section in sections:
        if section.has_key('n'):
            out += " " + section['n']
            if section.has_key('p'):
                out += " <br /> " + section['p']

    for inst in field_245_X:
        out += inst.get('a', '')
        if inst.has_key('b'):
            out += ' : ' + inst['b']
        if inst.has_key('s'):
            out += ' : ' + inst['s']

    for alt_title in alt_titles:
        if out:
            out += "<br /><strong><em>" + alt_title.get("a",
                                                        "") + "</em></strong>"
        else:
            out += "<strong>" + alt_title.get("a", "") + "</strong>"
        if alt_title.has_key('b'):
            out += ' : ' + alt_title['b']
        if alt_title.has_key('s'):
            out += ' : ' + alt_title['s']

    # Display edition statement only if other title were found
    if out != '' and edition_statement != '':
        out += " ; " + edition_statement

    if highlight == 'yes':
        from invenio import bibformat_utils
        out = bibformat_utils.highlight(
            out,
            bfo.search_pattern,
            prefix_tag="<span style='font-weight: bolder'>",
            suffix_tag='</style>')

    if bfo.field('960__a') == '40':
        out += "<br />"

    if link_title.lower() == 'yes':
        out = '<a href="%s/record/%s?ln=%s" class="titlelink">%s</a>' % \
              (CFG_SITE_URL,
               bfo.recID,
               bfo.lang,
               out)

    return out
def format_element(bfo, separator=" ", highlight='no'):
    """
    Prints the titles of a record. Makes a link to detailed record. Formats according to bibl.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    import cgi
    import re
    from invenio.urlutils import create_html_link
    from invenio.messages import gettext_set_language
    from invenio.config import CFG_SITE_URL

    _ = gettext_set_language(bfo.lang)  # load the right message language

    recid = bfo.control_field('001')
    ln = ''

    titles = []

    title_a = bfo.field('24510a')
    title_h = bfo.field('24510h')
    title_b = bfo.field('24510b')
    title_n = bfo.field('24510n')
    title_p = bfo.field('24510p')
    title_c = bfo.field('24510c')

    if len(title_a) == 0:
        title_a = bfo.field('245__a')
        title_h = bfo.field('245__h')
        title_b = bfo.field('245__b')
        title_n = bfo.field('245__n')
        title_p = bfo.field('245__p')
        title_c = bfo.field('245__c')

    if len(title_a) == 0:
        title_a = bfo.field('24511a')
        title_h = bfo.field('24511h')
        title_b = bfo.field('24511b')
        title_n = bfo.field('24511n')
        title_p = bfo.field('24511p')
        title_c = bfo.field('24511c')

    if len(title_a) == 0:
        title_a = bfo.field('24512a')
        title_h = bfo.field('24512h')
        title_b = bfo.field('24512b')
        title_n = bfo.field('24512n')
        title_p = bfo.field('24512p')
        title_c = bfo.field('24512c')

    if len(title_a) == 0:
        title_a = bfo.field('24513a')
        title_h = bfo.field('24513h')
        title_b = bfo.field('24513b')
        title_n = bfo.field('24513n')
        title_p = bfo.field('24513p')
        title_c = bfo.field('24513c')

    if len(title_a) == 0:
        title_a = bfo.field('24514a')
        title_h = bfo.field('24514h')
        title_b = bfo.field('24514b')
        title_n = bfo.field('24514n')
        title_p = bfo.field('24514p')
        title_c = bfo.field('24514c')

    if len(title_a) == 0:
        title_a = bfo.field('24515a')
        title_h = bfo.field('24515h')
        title_b = bfo.field('24515b')
        title_n = bfo.field('24515n')
        title_p = bfo.field('24515p')
        title_c = bfo.field('24515c')

    if len(title_a) == 0:
        title_a = bfo.field('24516a')
        title_h = bfo.field('24516h')
        title_b = bfo.field('24516b')
        title_n = bfo.field('24516n')
        title_p = bfo.field('24516p')
        title_c = bfo.field('24516c')

    if len(title_a) == 0:
        title_a = bfo.field('24517a')
        title_h = bfo.field('24517h')
        title_b = bfo.field('24517b')
        title_n = bfo.field('24517n')
        title_p = bfo.field('24517p')
        title_c = bfo.field('24517c')

    if len(title_a) == 0:
        title_a = bfo.field('24518a')
        title_h = bfo.field('24518h')
        title_b = bfo.field('24518b')
        title_n = bfo.field('24518n')
        title_p = bfo.field('24518p')
        title_c = bfo.field('24518c')

    if len(title_a) == 0:
        title_a = bfo.field('24519a')
        title_h = bfo.field('24519h')
        title_b = bfo.field('24519b')
        title_n = bfo.field('24519n')
        title_p = bfo.field('24519p')
        title_c = bfo.field('24519c')

    if len(title_a) == 0:
        title_a = bfo.field('24500a')
        title_h = bfo.field('24500h')
        title_b = bfo.field('24500b')
        title_n = bfo.field('24500n')
        title_p = bfo.field('24500p')
        title_c = bfo.field('24500c')

    if len(title_a) == 0:
        title_a = bfo.field('24501a')
        title_h = bfo.field('24501h')
        title_b = bfo.field('24501b')
        title_n = bfo.field('24501n')
        title_p = bfo.field('24501p')
        title_c = bfo.field('24501c')

    if len(title_a) == 0:
        title_a = bfo.field('24502a')
        title_h = bfo.field('24502h')
        title_b = bfo.field('24502b')
        title_n = bfo.field('24502n')
        title_p = bfo.field('24502p')
        title_c = bfo.field('24502c')

    if len(title_a) == 0:
        title_a = bfo.field('24503a')
        title_h = bfo.field('24503h')
        title_b = bfo.field('24503b')
        title_n = bfo.field('24503n')
        title_p = bfo.field('24503p')
        title_c = bfo.field('24503c')

    if len(title_a) == 0:
        title_a = bfo.field('24504a')
        title_h = bfo.field('24504h')
        title_b = bfo.field('24504b')
        title_n = bfo.field('24504n')
        title_p = bfo.field('24504p')
        title_c = bfo.field('24504c')

    if len(title_a) == 0:
        title_a = bfo.field('24505a')
        title_h = bfo.field('24505h')
        title_b = bfo.field('24505b')
        title_n = bfo.field('24505n')
        title_p = bfo.field('24505p')
        title_c = bfo.field('24505c')

    if len(title_a) == 0:
        title_a = bfo.field('24506a')
        title_h = bfo.field('24506h')
        title_b = bfo.field('24506b')
        title_n = bfo.field('24506n')
        title_p = bfo.field('24506p')
        title_c = bfo.field('24506c')

    if len(title_a) == 0:
        title_a = bfo.field('24507a')
        title_h = bfo.field('24507h')
        title_b = bfo.field('24507b')
        title_n = bfo.field('24507n')
        title_p = bfo.field('24507p')
        title_c = bfo.field('24507c')

    if len(title_a) == 0:
        title_a = bfo.field('24508a')
        title_h = bfo.field('24508h')
        title_b = bfo.field('24508b')
        title_n = bfo.field('24508n')
        title_p = bfo.field('24508p')
        title_c = bfo.field('24508c')

    if len(title_a) == 0:
        title_a = bfo.field('24509a')
        title_h = bfo.field('24509h')
        title_b = bfo.field('24509b')
        title_n = bfo.field('24509n')
        title_p = bfo.field('24509p')
        title_c = bfo.field('24509c')


#######################

    if len(title_a) > 0:
        title_a += ' ' + title_h
        title_a += ' ' + title_b
        title_a += ' ' + title_n
        title_a += ' ' + title_p
        titles.append(title_a)

    if len(titles) > 0:
        #Display 'Conference' title only if other titles were not found
        title = bfo.field('111__a')
        if len(title) > 0:
            titles.append(title_a)

    #titles = [cgi.escape(x) for x in titles]

    if highlight == 'yes':
        from invenio import bibformat_utils
        titles = [
            bibformat_utils.highlight(x, bfo.search_pattern) for x in titles
        ]

    lang = '?ln=' + bfo.lang
    target = '<a href="%s/record/%s%s">' % (CFG_SITE_URL, recid, lang)

    # make a detailed record link
    if len(title_c) > 0:
        return target + "<b>" + separator.join(
            titles) + "</b>" + "</a> " + title_c
    else:
        return target + "<b>" + separator.join(titles) + "</b>" + "</a> "
Exemplo n.º 30
0
            #    out += sentence + "."
            out += '. '.join(s_abstract)

            # Add final dot if needed
            if abstract_fr.endswith('.'):
                out += '.'

            if print_extension:
                out += " " + extension_fr

        else:
            out += abstract_fr

        out += suffix_fr

    if highlight == 'yes':
        out = bibformat_utils.highlight(out, bfo.search_pattern)

    if latex_to_html == 'yes':
        out = bibformat_utils.latex_to_html(out)

    return out


def escape_values(bfo):
    """
    Called by BibFormat in order to check if output of this element
    should be escaped.
    """
    return 0
Exemplo n.º 31
0
            #for sentence in s_abstract:
            #    out += sentence + "."
            out += '. '.join(s_abstract)

            # Add final dot if needed
            if abstract_fr.endswith('.'):
                out += '.'

            if print_extension:
                out += " "+extension_fr

        else:
            out += abstract_fr

        out += suffix_fr

    if highlight == 'yes':
        out = bibformat_utils.highlight(out, bfo.search_pattern)

    if latex_to_html == 'yes':
        out = bibformat_utils.latex_to_html(out)

    return out

def escape_values(bfo):
    """
    Called by BibFormat in order to check if output of this element
    should be escaped.
    """
    return 0
Exemplo n.º 32
0
def format_element(bfo, separator=" ", highlight='no'):
    """
    Prints the titles of a record.

    @param separator: separator between the different titles
    @param highlight: highlights the words corresponding to search query if set to 'yes'
    """
    titles = []

    title = bfo.field('24510a')
    title_remainder = bfo.field('24510b')
    edition_statement = bfo.field('25010a')
    title_tome = bfo.field('24510n')
    title_part = bfo.field('24510p')

    if len(title) == 0:
        title = bfo.field('245__a')
        title_remainder = bfo.field('245__b')
        edition_statement = bfo.field('250__a')
        title_tome = bfo.field('245__n')
        title_part = bfo.field('245__p')

    if len(title) == 0:
        title = bfo.field('24511a')
        title_remainder = bfo.field('24511b')
        edition_statement = bfo.field('25011a')
        title_tome = bfo.field('24511n')
        title_part = bfo.field('24511p')

    if len(title) == 0:
        title = bfo.field('24512a')
        title_remainder = bfo.field('24512b')
        edition_statement = bfo.field('25012a')
        title_tome = bfo.field('24512n')
        title_part = bfo.field('24512p')

    if len(title) == 0:
        title = bfo.field('24513a')
        title_remainder = bfo.field('24513b')
        edition_statement = bfo.field('25013a')
        title_tome = bfo.field('24513n')
        title_part = bfo.field('24513p')

    if len(title) == 0:
        title = bfo.field('24514a')
        title_remainder = bfo.field('24514b')
        edition_statement = bfo.field('25014a')
        title_tome = bfo.field('24514n')
        title_part = bfo.field('24514p')

    if len(title) == 0:
        title = bfo.field('24515a')
        title_remainder = bfo.field('24515b')
        edition_statement = bfo.field('25015a')
        title_tome = bfo.field('24515n')
        title_part = bfo.field('24515p')

    if len(title) == 0:
        title = bfo.field('24516a')
        title_remainder = bfo.field('24516b')
        edition_statement = bfo.field('25016a')
        title_tome = bfo.field('24516n')
        title_part = bfo.field('24516p')

    if len(title) == 0:
        title = bfo.field('24517a')
        title_remainder = bfo.field('24517b')
        edition_statement = bfo.field('25017a')
        title_tome = bfo.field('24517n')
        title_part = bfo.field('24517p')

    if len(title) == 0:
        title = bfo.field('24518a')
        title_remainder = bfo.field('24518b')
        edition_statement = bfo.field('25018a')
        title_tome = bfo.field('24518n')
        title_part = bfo.field('24518p')

    if len(title) == 0:
        title = bfo.field('24519a')
        title_remainder = bfo.field('24519b')
        edition_statement = bfo.field('25019a')
        title_tome = bfo.field('24519n')
        title_part = bfo.field('24519p')

    if len(title) == 0:
        title = bfo.field('24500a')
        title_remainder = bfo.field('24500b')
        edition_statement = bfo.field('25000a')
        title_tome = bfo.field('24500n')
        title_part = bfo.field('24500p')

    if len(title) == 0:
        title = bfo.field('24501a')
        title_remainder = bfo.field('24501b')
        edition_statement = bfo.field('25001a')
        title_tome = bfo.field('24501n')
        title_part = bfo.field('24501p')

    if len(title) == 0:
        title = bfo.field('24502a')
        title_remainder = bfo.field('24502b')
        edition_statement = bfo.field('25002a')
        title_tome = bfo.field('24502n')
        title_part = bfo.field('24502p')

    if len(title) == 0:
        title = bfo.field('24503a')
        title_remainder = bfo.field('24503b')
        edition_statement = bfo.field('25003a')
        title_tome = bfo.field('24503n')
        title_part = bfo.field('24503p')

    if len(title) == 0:
        title = bfo.field('24504a')
        title_remainder = bfo.field('24504b')
        edition_statement = bfo.field('25004a')
        title_tome = bfo.field('24504n')
        title_part = bfo.field('24504p')

    if len(title) == 0:
        title = bfo.field('24505a')
        title_remainder = bfo.field('24505b')
        edition_statement = bfo.field('25005a')
        title_tome = bfo.field('24505n')
        title_part = bfo.field('24505p')

    if len(title) == 0:
        title = bfo.field('24506a')
        title_remainder = bfo.field('24506b')
        edition_statement = bfo.field('25006a')
        title_tome = bfo.field('24506n')
        title_part = bfo.field('24506p')

    if len(title) == 0:
        title = bfo.field('24507a')
        title_remainder = bfo.field('24507b')
        edition_statement = bfo.field('25007a')
        title_tome = bfo.field('24507n')
        title_part = bfo.field('24507p')

    if len(title) == 0:
        title = bfo.field('24508a')
        title_remainder = bfo.field('24508b')
        edition_statement = bfo.field('25008a')
        title_tome = bfo.field('24508n')
        title_part = bfo.field('24508p')

    if len(title) == 0:
        title = bfo.field('24509a')
        title_remainder = bfo.field('24509b')
        edition_statement = bfo.field('25009a')
        title_tome = bfo.field('24509n')
        title_part = bfo.field('24509p')

    if len(title) > 0:
        if title_remainder:
            title += ': ' + title_remainder
            title = title.replace('::', ':')
        if len(title_tome) > 0:
            title += ", " + title_tome
        if len(title_part) > 0:
            title += ": " + title_part
            title = title.replace(':', ':')
        title = re.sub('/$', '', title)
        title = re.sub(':$', '', title)
        titles.append(title)

    title = bfo.field('0248_a')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246__a')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246__b')
    if len(title) > 0:
        titles.append(title)

    title = bfo.field('246_1a')
    if len(title) > 0:
        titles.append(title)

    if len(titles) > 0:
        #Display 'Conference' title only if other titles were not found
        title = bfo.field('111__a')
        if len(title) > 0:
            titles.append(title)

    #if '&x' in titles:

    #titles = [cgi.escape(x) for x in titles]

    if highlight == 'yes':
        from invenio import bibformat_utils
        titles = [
            bibformat_utils.highlight(x, bfo.search_pattern) for x in titles
        ]

    if len(edition_statement) > 0:
        #return separator.join(titles) + "; " + edition_statement
        tstring = separator.join(titles) + "; " + edition_statement
        if '&#' in tstring:
            tstring = cgi.escape(tstring)
        return tstring
    else:
        #return separator.join(titles)
        tstring = separator.join(titles)
        if not '&#' in tstring:
            tstring = cgi.escape(tstring)
        return tstring