def compare_revisions(rev1, rev2, recid): """Compare two revisions of a record.""" from invenio.legacy.bibedit.engine import (get_marcxml_of_revision_id, re_revdate_split) from invenio.legacy.bibrecord.xmlmarc2textmarc import create_marc_record from invenio.legacy.bibrecord import create_record from invenio.legacy.bibedit.utils import record_revision_exists from invenio.utils.text import show_diff person1 = "" person2 = "" if (not record_revision_exists(recid, rev1)) or \ (not record_revision_exists(recid, rev2)): return render_template("editor/revision_comparison_error.html") else: xml1 = get_marcxml_of_revision_id(recid, rev1) xml2 = get_marcxml_of_revision_id(recid, rev2) # Create MARC representations of the records marc1 = create_marc_record( create_record(xml1)[0], '', { "text-marc": 1, "aleph-marc": 0 }) marc2 = create_marc_record( create_record(xml2)[0], '', { "text-marc": 1, "aleph-marc": 0 }) comparison = show_diff( marc1, marc2, prefix="<pre>", suffix="</pre>", prefix_removed='<strong class="diff_field_deleted">', suffix_removed='</strong>', prefix_added='<strong class="diff_field_added">', suffix_added='</strong>') job_date1 = "%s-%s-%s %s:%s:%s" % re_revdate_split.search( rev1).groups() job_date2 = "%s-%s-%s %s:%s:%s" % re_revdate_split.search( rev2).groups() # Getting the author of each revision info1 = get_info_of_record_revision(recid, job_date1) info2 = get_info_of_record_revision(recid, job_date2) if info1: person1 = info1[0][1] if info2: person2 = info2[0][1] ctx = { "job_date1": job_date1, "job_date2": job_date2, "person1": person1, "person2": person2, "comparison": comparison } return render_template("editor/revision_comparison.html", **ctx)
def compare_revisions(rev1, rev2, recid): """Compare two revisions of a record.""" from invenio.legacy.bibedit.engine import (get_marcxml_of_revision_id, re_revdate_split) from invenio.legacy.bibrecord.xmlmarc2textmarc import create_marc_record from invenio.legacy.bibrecord import create_record from invenio.legacy.bibedit.utils import record_revision_exists from invenio.utils.text import show_diff person1 = "" person2 = "" if (not record_revision_exists(recid, rev1)) or \ (not record_revision_exists(recid, rev2)): return render_template("editor/revision_comparison_error.html") else: xml1 = get_marcxml_of_revision_id(recid, rev1) xml2 = get_marcxml_of_revision_id(recid, rev2) # Create MARC representations of the records marc1 = create_marc_record( create_record(xml1)[0], '', {"text-marc": 1, "aleph-marc": 0}) marc2 = create_marc_record( create_record(xml2)[0], '', {"text-marc": 1, "aleph-marc": 0}) comparison = show_diff( marc1, marc2, prefix="<pre>", suffix="</pre>", prefix_removed='<strong class="diff_field_deleted">', suffix_removed='</strong>', prefix_added='<strong class="diff_field_added">', suffix_added='</strong>') job_date1 = "%s-%s-%s %s:%s:%s" % re_revdate_split.search(rev1 ).groups() job_date2 = "%s-%s-%s %s:%s:%s" % re_revdate_split.search(rev2 ).groups() # Getting the author of each revision info1 = get_info_of_record_revision(recid, job_date1) info2 = get_info_of_record_revision(recid, job_date2) if info1: person1 = info1[0][1] if info2: person2 = info2[0][1] ctx = { "job_date1": job_date1, "job_date2": job_date2, "person1": person1, "person2": person2, "comparison": comparison } return render_template("editor/revision_comparison.html", **ctx)
def _get_formated_record(record_id, output_format, update_commands, language, outputTags="", checked=True, displayed_records=None): """Returns a record in a given format @param record_id: the ID of record to format @param output_format: an output format code (or short identifier for the output format) @param update_commands: list of commands used to update record contents @param language: the language to use to format the record @param outputTags: the tags to be shown to the user @param checked: is the record checked by the user? @param displayed_records: records to be displayed on a given page @returns: record formated to be displayed or None """ if update_commands and checked: # Modify the bibrecord object with the appropriate actions updated_record = _get_updated_record(record_id, update_commands) textmarc_options = {"aleph-marc":0, "correct-mode":1, "append-mode":0, "delete-mode":0, "insert-mode":0, "replace-mode":0, "text-marc":1} if record_id not in displayed_records: return old_record = search_engine.get_record(recid=record_id) old_record_textmarc = xmlmarc2textmarc.create_marc_record(old_record, sysno="", options=textmarc_options) if "hm" == output_format: if update_commands and checked: updated_record_textmarc = xmlmarc2textmarc.create_marc_record(updated_record, sysno="", options=textmarc_options) result = _get_record_diff(old_record_textmarc, updated_record_textmarc, outputTags, record_id) else: filter_tags = "All tags" not in outputTags and outputTags result = ['<pre>'] for line in old_record_textmarc.splitlines(): if not filter_tags or line.split()[0].replace('_', '') in outputTags: result.append("%09d " % record_id + line.strip()) result.append('</pre>') result = '\n'.join(result) else: if update_commands and checked: # No coloring of modifications in this case xml_record = bibrecord.record_xml_output(updated_record) else: xml_record = bibrecord.record_xml_output(old_record) result = bibformat.format_record(recID=None, of=output_format, xml_record=xml_record, ln=language) return result
def _create_marc(self, records_xml): """Creates MARC from MARCXML. @param records_xml: MARCXML containing information about the records @return: string containing information about the records in MARC format """ aleph_marc_output = "" records = bibrecord.create_records(records_xml) for (record, status_code, list_of_errors) in records: sysno_options = {"text-marc": 1} sysno = xmlmarc2textmarc.get_sysno_from_record( record, sysno_options) options = { "aleph-marc": 0, "correct-mode": 1, "append-mode": 0, "delete-mode": 0, "insert-mode": 0, "replace-mode": 0, "text-marc": 1 } aleph_record = xmlmarc2textmarc.create_marc_record( record, sysno, options) aleph_marc_output += aleph_record return aleph_marc_output
def _create_marc(records_xml): """Creates MARC from MARCXML. @param records_xml: MARCXML containing information about the records @return: string containing information about the records in MARC format """ aleph_marc_output = "" records = bibrecord.create_records(records_xml) for (record, dummy_status_code, dummy_list_of_errors) in records: sysno = "" options = {"aleph-marc":0, "correct-mode":1, "append-mode":0, "delete-mode":0, "insert-mode":0, "replace-mode":0, "text-marc":1} aleph_record = xmlmarc2textmarc.create_marc_record(record, sysno, options) aleph_marc_output += aleph_record return aleph_marc_output
def transform_record_to_marc(record, options={'text-marc':1, 'aleph-marc':0}): """ This function will transform a given bibrec record into marc using methods from xmlmarc2textmarc in invenio.utils.text. The function returns the record as a MARC string. @param record: bibrec structure for record to transform @type record: dict @param options: dictionary describing type of MARC record. Defaults to textmarc. @type options: dict @return resulting MARC record as string """ sysno = get_sysno_from_record(record, options) # Note: Record dict is copied as create_marc_record() perform deletions return create_marc_record(record.copy(), sysno, options)