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['a']] previous_recIDs = [] parameters = [] count = None publications_formatted = [] ## for every control number that this author has, find all the connected records for each one for control_no in control_nos: for ctrl_number_field_numbers in CFG_BIBAUTHORITY_RECORD_AUTHOR_CONTROL_NUMBER_FIELDS: parameters.append(ctrl_number_field_numbers + ":" + control_no.replace(" ","")) recIDs = [x for x in get_dependent_records_for_control_no(control_no) if x not in previous_recIDs] 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 = '' # print as many of the author's publications as the CFG_BIBAUTHORITY_PUBLICATION_VIEW_LIMIT allows for i in range(count if count<CFG_BIBAUTHORITY_PUBLICATION_VIEW_LIMIT else CFG_BIBAUTHORITY_PUBLICATION_VIEW_LIMIT): title = get_fieldvalues(recIDs[i],"245__a") if title: url_str = "/record/"+ str(recIDs[i]) prefix = prefix_pattern % url_str publications_formatted.append(prefix + title[0] + postfix) title = "<strong>" + _("Publication(s)") + "</strong>" if publications_formatted: content = "<ul><li>" + "</li><li> ".join(publications_formatted) + "</li></ul>" else: content = "<strong style='color:red'>Missing !</strong>" 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 prefix = prefix_pattern % url_str content += prefix + "See all " + str(count) + " publications..." + postfix return "<p>" + title + ": " + content + "</p>"
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['a']] previous_recIDs = [] parameters = [] count = None publications_formatted = [] ## for every control number that this author has, find all the connected records for each one for control_no in control_nos: for ctrl_number_field_numbers in CFG_BIBAUTHORITY_RECORD_AUTHOR_CONTROL_NUMBER_FIELDS: parameters.append(ctrl_number_field_numbers + ":" + control_no.replace(" ", "")) recIDs = [ x for x in get_dependent_records_for_control_no(control_no) if x not in previous_recIDs ] 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 = '' # print as many of the author's publications as the CFG_BIBAUTHORITY_PUBLICATION_VIEW_LIMIT allows for i in range( count if count < CFG_BIBAUTHORITY_PUBLICATION_VIEW_LIMIT else CFG_BIBAUTHORITY_PUBLICATION_VIEW_LIMIT): title = get_fieldvalues(recIDs[i], "245__a") if title: url_str = "/record/" + str(recIDs[i]) prefix = prefix_pattern % url_str publications_formatted.append(prefix + title[0] + postfix) title = "<strong>" + _("Publication(s)") + "</strong>" if publications_formatted: content = "<ul><li>" + "</li><li> ".join( publications_formatted) + "</li></ul>" else: content = "<strong style='color:red'>Missing !</strong>" 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 prefix = prefix_pattern % url_str content += prefix + "See all " + str(count) + " publications..." + postfix return "<p>" + title + ": " + content + "</p>"
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.base.i18n 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>"
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.base.i18n 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>"
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.base.i18n 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>"