[open-ils-commits] r964 - in servres/trunk/conifer: integration syrup templates/item (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Mon Aug 16 22:58:01 EDT 2010


Author: gfawcett
Date: 2010-08-16 22:57:59 -0400 (Mon, 16 Aug 2010)
New Revision: 964

Modified:
   servres/trunk/conifer/integration/uwindsor.py
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/templates/item/item_metadata.xhtml
Log:
various bib related bits.

Modified: servres/trunk/conifer/integration/uwindsor.py
===================================================================
--- servres/trunk/conifer/integration/uwindsor.py	2010-08-16 23:28:46 UTC (rev 963)
+++ servres/trunk/conifer/integration/uwindsor.py	2010-08-17 02:57:59 UTC (rev 964)
@@ -46,7 +46,7 @@
 
 
 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 @@
     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 @@
     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

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2010-08-16 23:28:46 UTC (rev 963)
+++ servres/trunk/conifer/syrup/models.py	2010-08-17 02:57:59 UTC (rev 964)
@@ -559,6 +559,14 @@
     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):

Modified: servres/trunk/conifer/templates/item/item_metadata.xhtml
===================================================================
--- servres/trunk/conifer/templates/item/item_metadata.xhtml	2010-08-16 23:28:46 UTC (rev 963)
+++ servres/trunk/conifer/templates/item/item_metadata.xhtml	2010-08-17 02:57:59 UTC (rev 964)
@@ -63,5 +63,9 @@
 	      </table>
 	    </div>
     </div>
+    <div py:if="item.bib_id and gethook('bib_id_to_url')"
+	 py:with="url=callhook('bib_id_to_url', item.bib_id)">
+      <a py:if="url" href="${url}">View catalogue entry</a>
+    </div>
   </body>
 </html>



More information about the open-ils-commits mailing list