def merge_record_with_template(rec, template_name): """ Extend the record rec with the contents of the template and return it""" template = get_record_template(template_name) if not template: return template_bibrec = create_record(template)[0] for field_tag in template_bibrec: if not record_has_field(rec, field_tag): for field_instance in template_bibrec[field_tag]: record_add_field(rec, field_tag, field_instance[1], field_instance[2], subfields=field_instance[0]) else: for template_field_instance in template_bibrec[field_tag]: subfield_codes_template = field_get_subfield_codes( template_field_instance) for field_instance in rec[field_tag]: subfield_codes = field_get_subfield_codes(field_instance) for code in subfield_codes_template: if code not in subfield_codes: field_add_subfield( field_instance, code, field_get_subfield_values( template_field_instance, code)[0]) return rec
def merge_record_with_template(rec, template_name, is_hp_record=False): """ Extend the record rec with the contents of the template and return it""" template = get_record_template(template_name) if not template: return template_bibrec = create_record(template)[0] # if the record is a holding pen record make all subfields volatile if is_hp_record: record_make_all_subfields_volatile(template_bibrec) for field_tag in template_bibrec: if not record_has_field(rec, field_tag): for field_instance in template_bibrec[field_tag]: record_add_field(rec, field_tag, field_instance[1], field_instance[2], subfields=field_instance[0]) else: for template_field_instance in template_bibrec[field_tag]: subfield_codes_template = field_get_subfield_codes( template_field_instance) for field_instance in rec[field_tag]: subfield_codes = field_get_subfield_codes(field_instance) for code in subfield_codes_template: if code not in subfield_codes: field_add_subfield( field_instance, code, field_get_subfield_values( template_field_instance, code)[0]) record_order_subfields(rec) return rec
def merge_record_with_template(rec, template_name, is_hp_record=False): """ Extend the record rec with the contents of the template and return it""" template = get_record_template(template_name) if not template: return template_bibrec = create_record(template)[0] # if the record is a holding pen record make all subfields volatile if is_hp_record: record_make_all_subfields_volatile(template_bibrec) for field_tag in template_bibrec: if not record_has_field(rec, field_tag): for field_instance in template_bibrec[field_tag]: record_add_field(rec, field_tag, field_instance[1], field_instance[2], subfields=field_instance[0]) else: for template_field_instance in template_bibrec[field_tag]: subfield_codes_template = field_get_subfield_codes(template_field_instance) for field_instance in rec[field_tag]: subfield_codes = field_get_subfield_codes(field_instance) for code in subfield_codes_template: if code not in subfield_codes: field_add_subfield(field_instance, code, field_get_subfield_values(template_field_instance, code)[0]) return rec
def merge_record_with_template(rec, template_name): """ Extend the record rec with the contents of the template and return it""" template = get_record_template(template_name) template_bibrec = create_record(template)[0] for field_tag in template_bibrec: if not record_has_field(rec, field_tag): for field_instance in template_bibrec[field_tag]: record_add_field(rec, field_tag, field_instance[1], field_instance[2], subfields=field_instance[0]) else: for template_field_instance in template_bibrec[field_tag]: subfield_codes_template = field_get_subfield_codes(template_field_instance) for field_instance in rec[field_tag]: subfield_codes = field_get_subfield_codes(field_instance) for code in subfield_codes_template: if code not in subfield_codes: field_add_subfield( field_instance, code, field_get_subfield_values(template_field_instance, code)[0] ) return rec
def add_record_cnum(recid, uid): """ Check if the record has already a cnum. If not generate a new one and return the result @param recid: recid of the record under check. Used to retrieve cache file @type recid: int @param uid: id of the user. Used to retrieve cache file @type uid: int @return: None if cnum already present, new cnum otherwise @rtype: None or string """ # Import placed here to avoid circular dependency from invenio.sequtils_cnum import CnumSeq, ConferenceNoStartDateError record_revision, record, pending_changes, deactivated_hp_changes, \ undo_list, redo_list = get_cache_file_contents(recid, uid)[1:] record_strip_empty_volatile_subfields(record) # Check if record already has a cnum tag_111__g_content = record_get_field_value(record, "111", " ", " ", "g") if tag_111__g_content: return else: cnum_seq = CnumSeq() try: new_cnum = cnum_seq.next_value( xml_record=wash_for_xml(print_rec(record))) except ConferenceNoStartDateError: return None field_add_subfield(record['111'][0], 'g', new_cnum) update_cache_file_contents(recid, uid, record_revision, record, \ pending_changes, \ deactivated_hp_changes, \ undo_list, redo_list) return new_cnum
def add_record_cnum(recid, uid): """ Check if the record has already a cnum. If not generate a new one and return the result @param recid: recid of the record under check. Used to retrieve cache file @type recid: int @param uid: id of the user. Used to retrieve cache file @type uid: int @return: None if cnum already present, new cnum otherwise @rtype: None or string """ # Import placed here to avoid circular dependency from invenio.sequtils_cnum import CnumSeq, ConferenceNoStartDateError record_revision, record, pending_changes, deactivated_hp_changes, \ undo_list, redo_list = get_cache_contents(recid, uid)[1:] record_strip_empty_volatile_subfields(record) # Check if record already has a cnum tag_111__g_content = record_get_field_value(record, "111", " ", " ", "g") if tag_111__g_content: return else: cnum_seq = CnumSeq() try: new_cnum = cnum_seq.next_value(xml_record=wash_for_xml(print_rec(record))) except ConferenceNoStartDateError: return None field_add_subfield(record['111'][0], 'g', new_cnum) update_cache_contents(recid, uid, record_revision, record, pending_changes, deactivated_hp_changes, undo_list, redo_list) return new_cnum
def extend_author_field(author_field, cds_id): """Extend author datafield by CDS authority id and Beard tag. Extends the author datafield by the MARC subfields $$0:AUTHOR|(CDS)<cds_id> $$9:#BEARD# if $$0:AUTHOR|(CDS)<cds_id> does not exist in `author_field`. :param author_field: Example: # from invenio.search_engine import get_record # from invenio.bibrecord import record_get_field_instances # record = get_record(2150939) # author_field = record_get_field_instances(record, "100")[0] author_field = ([('a', 'Ellis, John'), ('u', "King's Coll. London"), ('u', 'CERN')], ' ', ' ', '', 32) :param str cds_id: sequence of numbers representing the CDS id Example: cds_id = '2108556' :result: Example: author_field = ([('a', 'Ellis, John'), ('u', "King's Coll. London"), ('u', 'CERN'), ('0', 'AUTHOR|(CDS)2108556'), ('9', '#BEARD#')], ' ', ' ', '', 32) :return: True, if `author_field` has been updated, False otherwise """ cds_authority_id = "AUTHOR|(CDS){0}".format(cds_id) if cds_authority_id not in field_get_subfield_values(author_field, '0'): field_add_subfield(author_field, "0", cds_authority_id) field_add_subfield(author_field, "9", "#BEARD#") return True return False