From 2d53c1b55e126f1961f47204017b2588d1a6e39e Mon Sep 17 00:00:00 2001 From: gfawcett Date: Tue, 17 Aug 2010 02:57:59 +0000 Subject: [PATCH] various bib related bits. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@964 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/integration/uwindsor.py | 29 ++++++++++++++++++++++++----- conifer/syrup/models.py | 8 ++++++++ conifer/templates/item/item_metadata.xhtml | 4 ++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/conifer/integration/uwindsor.py b/conifer/integration/uwindsor.py index 8721202..b094531 100644 --- a/conifer/integration/uwindsor.py +++ b/conifer/integration/uwindsor.py @@ -46,7 +46,7 @@ initialize(EG_BASE) def item_status(item): - if 'psychology' in item.title.lower(): + if item.bib_id and item.bib_id[-1] in '02468': return (8, 4, 2) else: return (2, 0, 0) @@ -74,6 +74,23 @@ def bib_id_to_marcxml(bib_id): except: return None +def marc_to_bib_id(marc_string): + """ + Given a MARC record, return either a bib ID or None, if no bib ID can be + found. + """ + dct = M.marcxml_to_dictionary(marc_string) + bib_id = dct.get('901c') + return bib_id + +def bib_id_to_url(bib_id): + """ + Given a bib ID, return either a URL for examining the bib record, or None. + """ + if bib_id: + return ('http://windsor.concat.ca/opac/en-US' + '/skin/default/xml/rdetail.xml?r=%s&l=1&d=0' % bib_id) + def get_better_copy_of_marc(marc_string): """ This function takes a MARCXML record and returns either the same @@ -84,11 +101,13 @@ def get_better_copy_of_marc(marc_string): returns a MARCXML record with broken character encoding. This function declares a point at which we can work around that server. """ - dct = M.marcxml_to_dictionary(marc_string) - bib_id = dct.get('901c') + bib_id = marc_to_bib_id(marc_string) better = bib_id_to_marcxml(bib_id) - return better or marc_string - + # don't return the "better" record if there's no 901c in it... + if better and ('901c' in M.marcxml_to_dictionary(better)): + return better + return ET.fromstring(marc_string) + def marcxml_to_url(marc_string): """ Given a MARC record, return either a URL (representing the diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index afa4cc6..200d554 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -559,6 +559,14 @@ class Item(BaseModel): class Meta: ordering = ['title', 'author', 'published'] + def save(self, *args, **kwargs): + # extract the bib ID from the MARC record if possible (and necessary) + if self.marcxml and not self.bib_id: + maybe_bib = callhook('marc_to_bib_id', self.marcxml) + if maybe_bib: + self.bib_id = maybe_bib + super(Item, self).save(*args, **kwargs) + #-------------------------------------------------- # MARC def marc_as_dict(self): diff --git a/conifer/templates/item/item_metadata.xhtml b/conifer/templates/item/item_metadata.xhtml index d5b591f..d4d1ad1 100644 --- a/conifer/templates/item/item_metadata.xhtml +++ b/conifer/templates/item/item_metadata.xhtml @@ -63,5 +63,9 @@ is_editor = site.can_edit(request.user) +
+ View catalogue entry +
-- 2.11.0