コード例 #1
0
ファイル: bfe_publisher.py プロジェクト: BessemAamira/invenio
def format_element(bfo):
    """
    Prints the publisher name

    @see: place.py, date.py, reprints.py, imprint.py, pagination.py
    """

    publisher = bfo.field("260__b")
    control_no = bfo.field("260__0")

    if publisher != "sine nomine":
        if control_no:
            recIDs = get_low_level_recIDs_from_control_no(control_no)
            if len(recIDs):
                publisher = (
                    '<a href="'
                    + CFG_SITE_URL
                    + "/record/"
                    + str(recIDs[0])
                    + "?ln="
                    + bfo.lang
                    + '">'
                    + publisher
                    + "</a>"
                )
        return publisher
コード例 #2
0
 def test_bibauthority_get_low_level_recIDs(self):
     """bibauthority - test get_low_level_recIDs_from_control_no()"""
     _type = CFG_BIBAUTHORITY_TYPE_NAMES['INSTITUTE']
     control_no = _type + CFG_BIBAUTHORITY_PREFIX_SEP + "(SzGeCERN)iii0002"
     recIDs = [121]
     self.assertEqual(get_low_level_recIDs_from_control_no(control_no),
                      recIDs)
コード例 #3
0
def format_element(bfo):
    """
    HTML Affiliation display
    """
    affiliations = bfo.fields('909C1', repeatable_subfields_p=True)
    out = ""
    for affiliation_dict in affiliations:
        if 'u' in affiliation_dict:
            recIDs = []
            affiliation = affiliation_dict['u'][0]
            control_nos = affiliation_dict.get('0')
            for control_no in control_nos or []:
                recIDs.extend(get_low_level_recIDs_from_control_no(control_no))
            affiliation = cgi.escape(affiliation)
            if len(recIDs) == 1:
                affiliation = '<a href="' + CFG_SITE_URL + \
                              '/record/' + str(recIDs[0]) + \
                              '?ln=' + bfo.lang + \
                              '">' + affiliation + '</a>'
            elif len(recIDs) > 1:
                affiliation = '<a href="' + CFG_SITE_URL + \
                              '/search?' + \
                              'p=recid:' +  " or recid:".join([str(_id) for _id in recIDs]) + \
                              '&amp;c=' + CFG_SITE_NAME + \
                              '&amp;c=' + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                              '&amp;ln=' + bfo.lang + \
                              '">' + affiliation + '</a>'

            out += affiliation + "       "

    if out:
        return "<br/>" + out
コード例 #4
0
 def test_bibauthority_get_low_level_recIDs(self):
     """bibauthority - test get_low_level_recIDs_from_control_no()"""
     _type = CFG_BIBAUTHORITY_TYPE_NAMES['INSTITUTE']
     control_no = _type + CFG_BIBAUTHORITY_PREFIX_SEP + "(SzGeCERN)iii0002"
     recIDs = [121]
     self.assertEqual(get_low_level_recIDs_from_control_no(control_no),
                      recIDs)
コード例 #5
0
def format_element(bfo):
    """
    Prints the publisher name

    @see: place.py, date.py, reprints.py, imprint.py, pagination.py
    """

    publisher = bfo.field('260__b')
    control_no = bfo.field('260__0')

    if publisher != "sine nomine":
        if control_no:
            recIDs = get_low_level_recIDs_from_control_no(control_no)
            if len(recIDs):
                publisher = '<a href="' + CFG_SITE_URL + '/record/' + \
                            str(recIDs[0]) + \
                            '?ln=' + bfo.lang + \
                            '">' + publisher + '</a>'
        return publisher
コード例 #6
0
ファイル: bfe_authors.py プロジェクト: MinnSoe/invenio
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)
コード例 #7
0
def format_element(bfo):
    """ Prints the control number of an author authority record in HTML.
    By default prints brief version.

    @param brief: whether the 'brief' rather than the 'detailed' format
    @type brief: 'yes' or 'no'
    """

    from invenio.messages import gettext_set_language
    _ = gettext_set_language(bfo.lang)    # load the right message language

    control_nos = [d['a'] for d in bfo.fields('035__') if d.get('a')]
    control_nos.extend([d['a'] for d in bfo.fields('970__') if d.get('a')])

    authority_type = [d.get('a') for d in bfo.fields('980__') if d.get('a') and d.get('a')!=authority_identifier]
    if authority_type and type(authority_type) is list:
        authority_type = authority_type[0]

    related_control_number_fields = ['510','970']
    related_control_number_fields.extend(control_number_fields.get(authority_type,[]))
    control_nos_formatted = []
    for control_no in control_nos:
        recIDs = get_dependent_records_for_control_no(control_no)
        count = len(recIDs)
        count_string = str(count) + " dependent records"
        from urllib import quote
        # if we have dependent records, provide a link to them
        if count:
            prefix_pattern = "<a href='" + CFG_SITE_URL + "%s" + "'>"
            postfix = "</a>"
            url_str = ''
            # we have multiple dependent records
            if count > 1:
                # joining control_nos might be more helpful for the user
                # than joining recIDs... or maybe not...
                parameters = []
                for control_number_field in related_control_number_fields:
                    parameters.append(control_number_field + ":" + control_no )
                p_val = quote(" or ".join(parameters))
                # include "&c=" parameter for bibliographic records
                # and one "&c=" parameter for authority records
                url_str = \
                    "/search" + \
                    "?p=" + p_val + \
                    "&c=" + quote(CFG_SITE_NAME) + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            # we have exactly one dependent record
            elif count == 1:
                url_str = "/record/" + str(recIDs[0])

            prefix = prefix_pattern % (url_str)
            count_string = prefix + count_string + postfix
        #assemble the html and append to list
        html_str = control_no + " (" + count_string + ")"

        # check if there are more than one authority record with the same
        # control number. If so, warn the user about this inconsistency.
        # TODO: hide this warning from unauthorized users
        my_recIDs = get_low_level_recIDs_from_control_no(control_no)
        if len(my_recIDs) > 1:
            url_str = \
                    "/search" + \
                    "?p=" + CFG_BIBAUTHORITY_RECORD_CONTROL_NUMBER_FIELD + ":" + control_no + \
                    "&c=" + quote(CFG_SITE_NAME) + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            html_str += \
                ' <span style="color:red">' + \
                '(Warning, there is currently ' + \
                '<a href="' + url_str + '">more than one authority record</a> ' + \
                'with this Control Number)' + \
                '</span>'

        control_nos_formatted.append(html_str)

    title = "<strong>" + _("Control Number(s)") + "</strong>"
    if control_nos_formatted:
        content = "<ul><li>" + "</li><li> ".join(control_nos_formatted) + "</li></ul>"
    else:
        content = "<strong style='color:red'>Missing !</strong>"

    return "<p>" + title + ": " + content + "</p>"
コード例 #8
0
ファイル: bfe_authors.py プロジェクト: chokribr/inveniotest
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)
コード例 #9
0
def format_element(bfo):
    """ Prints the control number of an author authority record in HTML. 
    By default prints brief version.

    @param brief: whether the 'brief' rather than the 'detailed' format
    @type brief: 'yes' or 'no'
    """

    from invenio.messages import gettext_set_language
    _ = gettext_set_language(bfo.lang)  # load the right message language

    control_nos = [d['a'] for d in bfo.fields('035__')]
    control_nos = filter(None, control_nos)  # fastest way to remove empty ""s

    control_nos_formatted = []
    for control_no in control_nos:
        #        recIDs = []
        #        types = guess_authority_types(bfo.recID)
        #        # control_no example: AUTHOR:(CERN)aaa0005"
        #        control_nos = [(type + CFG_BIBAUTHORITY_PREFIX_SEP + control_no) for type in types]
        #        for control_no in control_nos:
        #            recIDs.extend(list(search_pattern(p='"' + control_no + '"')))
        recIDs = get_dependent_records_for_control_no(control_no)
        count = len(recIDs)
        count_string = str(count) + " dependent records"

        # if we have dependent records, provide a link to them
        if count:
            prefix_pattern = "<a href='" + CFG_SITE_URL + "%s" + "'>"
            postfix = "</a>"
            url_str = ''
            # we have multiple dependent records
            if count > 1:
                # joining control_nos might be more helpful for the user
                # than joining recIDs... or maybe not...
                #                p_val = '"' + '" or "'.join(control_nos) + '"' # more understandable for the user
                p_val = "recid:" + ' or recid:'.join(
                    [str(recID) for recID in recIDs])  # more efficient
                # include "&c=" parameter for bibliographic records
                # and one "&c=" parameter for authority records
                url_str = \
                    "/search" + \
                    "?p=" + p_val + \
                    "&c=" + CFG_SITE_NAME + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            # we have exactly one dependent record
            elif count == 1:
                url_str = "/record/" + str(recIDs[0])

            prefix = prefix_pattern % (url_str)
            count_string = prefix + count_string + postfix
        #assemble the html and append to list
        html_str = control_no + " (" + count_string + ")"

        # check if there are more than one authority record with the same
        # control number. If so, warn the user about this inconsistency.
        # TODO: hide this warning from unauthorized users
        my_recIDs = get_low_level_recIDs_from_control_no(control_no)
        if len(my_recIDs) > 1:
            url_str = \
                    "/search" + \
                    "?p=" + "recid:" + 'or recid:'.join([str(_id) for _id in my_recIDs]) + \
                    "&c=" + CFG_SITE_NAME + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            html_str += \
                ' <span style="color:red">' + \
                '(Warning, there is currently ' + \
                '<a href="' + url_str + '">more than one authority record</a> ' + \
                'with this Control Number)' + \
                '</span>'

        control_nos_formatted.append(html_str)

    title = "<strong>" + _("Control Number(s)") + "</strong>"
    content = ", ".join(control_nos_formatted) \
        or "<strong style='color:red'>Missing !</strong>"

    return "<p>" + title + ": " + content + "</p>"
コード例 #10
0
def format_element(bfo):
    """ Prints the control number of an author authority record in HTML. 
    By default prints brief version.

    @param brief: whether the 'brief' rather than the 'detailed' format
    @type brief: 'yes' or 'no'
    """

    from invenio.messages import gettext_set_language
    _ = gettext_set_language(bfo.lang)    # load the right message language

    control_nos = [d['a'] for d in bfo.fields('035__')]
    control_nos = filter(None, control_nos) # fastest way to remove empty ""s
        
    control_nos_formatted = []
    for control_no in control_nos:
#        recIDs = []
#        types = guess_authority_types(bfo.recID)
#        # control_no example: AUTHOR:(CERN)aaa0005"
#        control_nos = [(type + CFG_BIBAUTHORITY_PREFIX_SEP + control_no) for type in types]
#        for control_no in control_nos:
#            recIDs.extend(list(search_pattern(p='"' + control_no + '"')))
        recIDs = get_dependent_records_for_control_no(control_no)
        count = len(recIDs)
        count_string = str(count) + " dependent records"
        
        # if we have dependent records, provide a link to them
        if count:
            prefix_pattern = "<a href='" + CFG_SITE_URL + "%s" + "'>"
            postfix = "</a>"
            url_str = ''
            # we have multiple dependent records
            if count > 1:
                # joining control_nos might be more helpful for the user 
                # than joining recIDs... or maybe not...
#                p_val = '"' + '" or "'.join(control_nos) + '"' # more understandable for the user
                p_val = "recid:" + ' or recid:'.join([str(recID) for recID in recIDs]) # more efficient
                # include "&c=" parameter for bibliographic records 
                # and one "&c=" parameter for authority records
                url_str = \
                    "/search" + \
                    "?p=" + p_val + \
                    "&c=" + CFG_SITE_NAME + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            # we have exactly one dependent record
            elif count == 1:
                url_str = "/record/" + str(recIDs[0])
            
            prefix = prefix_pattern % (url_str)
            count_string = prefix + count_string + postfix
        #assemble the html and append to list
        html_str = control_no + " (" + count_string + ")"
        
        # check if there are more than one authority record with the same
        # control number. If so, warn the user about this inconsistency. 
        # TODO: hide this warning from unauthorized users
        my_recIDs = get_low_level_recIDs_from_control_no(control_no)
        if len(my_recIDs) > 1:
            url_str = \
                    "/search" + \
                    "?p=" + "recid:" + 'or recid:'.join([str(_id) for _id in my_recIDs]) + \
                    "&c=" + CFG_SITE_NAME + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            html_str += \
                ' <span style="color:red">' + \
                '(Warning, there is currently ' + \
                '<a href="' + url_str + '">more than one authority record</a> ' + \
                'with this Control Number)' + \
                '</span>'
        
        control_nos_formatted.append(html_str)
    
    title = "<strong>" + _("Control Number(s)") + "</strong>"
    content = ", ".join(control_nos_formatted) \
        or "<strong style='color:red'>Missing !</strong>"
    
    return "<p>" + title + ": " + content + "</p>"
コード例 #11
0
def format_element(bfo):
    """ Prints the control number of an author authority record in HTML.
    By default prints brief version.

    @param brief: whether the 'brief' rather than the 'detailed' format
    @type brief: 'yes' or 'no'
    """

    from invenio.messages import gettext_set_language
    _ = gettext_set_language(bfo.lang)  # load the right message language

    control_nos = [d['a'] for d in bfo.fields('035__') if d.get('a')]
    control_nos.extend([d['a'] for d in bfo.fields('970__') if d.get('a')])

    authority_type = [
        d.get('a') for d in bfo.fields('980__')
        if d.get('a') and d.get('a') != authority_identifier
    ]
    if authority_type and type(authority_type) is list:
        authority_type = authority_type[0]

    related_control_number_fields = ['510', '970']
    related_control_number_fields.extend(
        control_number_fields.get(authority_type, []))
    control_nos_formatted = []
    for control_no in control_nos:
        recIDs = get_dependent_records_for_control_no(control_no)
        count = len(recIDs)
        count_string = str(count) + " dependent records"
        from urllib import quote
        # if we have dependent records, provide a link to them
        if count:
            prefix_pattern = "<a href='" + CFG_SITE_URL + "%s" + "'>"
            postfix = "</a>"
            url_str = ''
            # we have multiple dependent records
            if count > 1:
                # joining control_nos might be more helpful for the user
                # than joining recIDs... or maybe not...
                parameters = []
                for control_number_field in related_control_number_fields:
                    parameters.append(control_number_field + ":" + control_no)
                p_val = quote(" or ".join(parameters))
                # include "&c=" parameter for bibliographic records
                # and one "&c=" parameter for authority records
                url_str = \
                    "/search" + \
                    "?p=" + p_val + \
                    "&c=" + quote(CFG_SITE_NAME) + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            # we have exactly one dependent record
            elif count == 1:
                url_str = "/record/" + str(recIDs[0])

            prefix = prefix_pattern % (url_str)
            count_string = prefix + count_string + postfix
        #assemble the html and append to list
        html_str = control_no + " (" + count_string + ")"

        # check if there are more than one authority record with the same
        # control number. If so, warn the user about this inconsistency.
        # TODO: hide this warning from unauthorized users
        my_recIDs = get_low_level_recIDs_from_control_no(control_no)
        if len(my_recIDs) > 1:
            url_str = \
                    "/search" + \
                    "?p=" + CFG_BIBAUTHORITY_RECORD_CONTROL_NUMBER_FIELD + ":" + control_no + \
                    "&c=" + quote(CFG_SITE_NAME) + \
                    "&c=" + CFG_BIBAUTHORITY_AUTHORITY_COLLECTION_NAME + \
                    "&sc=1" + \
                    "&ln=" + bfo.lang
            html_str += \
                ' <span style="color:red">' + \
                '(Warning, there is currently ' + \
                '<a href="' + url_str + '">more than one authority record</a> ' + \
                'with this Control Number)' + \
                '</span>'

        control_nos_formatted.append(html_str)

    title = "<strong>" + _("Control Number(s)") + "</strong>"
    if control_nos_formatted:
        content = "<ul><li>" + "</li><li> ".join(
            control_nos_formatted) + "</li></ul>"
    else:
        content = "<strong style='color:red'>Missing !</strong>"

    return "<p>" + title + ": " + content + "</p>"