$code: names = { "marc_baclac": "Library and Archives Canada", "marc_dnb_202006": "Deutsche Nationalbibliothek", "marc_loc_updates": "Library of Congress", "marc_loc_2016": "Library of Congress", "marc_loc_2019": "Library of Congress", "marc_records_scriblio_net": "Scriblio", "talis_openlibrary_contribution": "Talis", "unc_catalog_marc": "University of North Carolina", "marc_oregon_summit_records": "Oregon Libraries", "marc_western_washington_univ": "Western Washington University", "marc_university_of_toronto": "University of Toronto", "bpl_marc": "Boston Public Library", "marc_boston_college": "Boston College", "marc_miami_univ_ohio": "Miami University of Ohio", "marc_laurentian": "The Laurentian Library", "wfm_bk_marc": "Buffalo State College", "CollingswoodLibraryMarcDump10-27-2008": "Collingswood Public Library", "hollis_marc": "Harvard's HOLLIS catalog", "marc_ithaca_college": "Ithaca College Library", "marc_binghamton_univ": "Binghamton University", "marc_upei": "University of Prince Edward Island", "marc_marygrove": "Marygrove College", } for i in range(1, 17): names["SanFranPL%02d" % i] = "San Francisco Public Library" def get_source_record(record_id): if '/' not in record_id and '_meta.mrc:' in record_id: record_id = 'ia:' + record_id.split('_')[0] item = record_id.split("/")[0] url = "/show-records/" + record_id if item.startswith("ia:"): source_name = "Internet Archive" source_url = "//archive.org/details/" + item[3:] elif item.startswith("promise:"): source_name = "Promise Item" source_url = "https://archive.org/details/" + item[8:] elif item.startswith("amazon:"): source_name = "amazon.com" source_url = "https://www.amazon.com/?tag=" + affiliate_id('amazon') elif item.startswith("bwb:"): source_name = "Better World Books" source_url = "https://www.betterworldbooks.com/" elif item.startswith("google_books:"): source_name = "Google Books" source_url = "https://books.google.com/" elif item.startswith("idb:") or item.startswith("osp:"): source_name = "ISBNdb" source_url = "https://isbndb.com/" elif item.startswith("openalex:"): source_name = "OpenAlex" source_url = "https://openalex.org/" + item[9:] else: source_name = names.get(item, item) source_url = "//archive.org/details/" + item return storage(id=record_id, url=url, source_name=source_name, source_url=source_url) def link(url, label): return '' + label + '' if url else label def get_source_html(record_id): record_type = _('record') if record_id.startswith('marc:'): record_id = record_id[5:] if record_id.startswith('marc'): record_type = _('MARC record') record = get_source_record(record_id) if record.source_name == 'Internet Archive': record_type = _('item record') if record.source_name in ('Promise Item', 'ISBNdb', 'OpenAlex'): return link(record.source_url, record.source_name) else: return link(record.source_url, record.source_name) + ' ' + link(record.url, record_type) $var get_source_record = get_source_record $var get_source_html = get_source_html