[open-ils-commits] r1296 - servres/trunk/conifer/integration (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Apr 2 20:37:40 EDT 2011


Author: gfawcett
Date: 2011-04-02 20:37:39 -0400 (Sat, 02 Apr 2011)
New Revision: 1296

Modified:
   servres/trunk/conifer/integration/uwindsor.py
Log:
conifer/integration/uwindsor.py: cat_search cleanup

This also addresses the unicode-related TypeError that C/W MARS encountered.

Modified: servres/trunk/conifer/integration/uwindsor.py
===================================================================
--- servres/trunk/conifer/integration/uwindsor.py	2011-04-01 03:09:34 UTC (rev 1295)
+++ servres/trunk/conifer/integration/uwindsor.py	2011-04-03 00:37:39 UTC (rev 1296)
@@ -233,11 +233,13 @@
             pass          # fail silently in production if there's an opensrf or time related error.
     return None
 
+CAT_SEARCH_ORG_UNIT = 106
+
 def cat_search(query, start=1, limit=10):
-    bibid=0
-    # TODO: check whether there would be exceptions to numeric 14 digit barcode 
-    barcode = re.search('\d{14}', query.strip())
-    bc = 0
+    barcode = 0
+    bibid   = 0
+    is_barcode = re.search('\d{14}', query)
+
     if query.startswith(EG_BASE):
         # query is an Evergreen URL
 	# snag the bibid at this point
@@ -247,21 +249,19 @@
 			bibid = params[key]
         results = M.marcxml_to_records(I.url_to_marcxml(query))
         numhits = len(results)
-    elif barcode:
+    elif is_barcode:
 	results = []
 	numhits = 0
-	# print "bc", bc.group(0)
-	bc = barcode.group(0)
-        bib = E1('open-ils.search.bib_id.by_barcode', bc)
+	barcode = query.strip()
+        bib = E1('open-ils.search.bib_id.by_barcode', barcode)
 	if bib:
 		bibid = bib
-		print "bibid", bib
 		copy = E1('open-ils.supercat.record.object.retrieve', bib)
-		print "copy", copy
-		rec = copy[0]
-		print "rec", rec
-		marc = unicode(rec['marc'], 'utf-8')
-		print "marc", marc
+		marc = copy[0]['marc']
+                # In some institutions' installations, 'marc' is a string; in
+                # others it's unicode. Convert to unicode if necessary.
+                if not isinstance(marc, unicode):
+                    marc = unicode(marc, 'utf-8')
                 tree = M.marcxml_to_records(marc)[0]
                 results.append(tree)
 		numhits = 1
@@ -272,17 +272,23 @@
             results, numhits = PZ.search(cat_host, cat_port, cat_db, query, start, limit)
         else:                   # use opensrf
             superpage = E1('open-ils.search.biblio.multiclass.query',
-                   {"org_unit":106,"depth":1,"limit":limit,"offset":start-1,"visibility_limit":3000,
-                    "default_class":"keyword"},
-                   query, 1)
+                           {'org_unit': CAT_SEARCH_ORG_UNIT,
+                            'depth': 1, 'limit': limit, 'offset': start-1,
+                            'visibility_limit': 3000,
+                            'default_class': 'keyword'},
+                           query, 1)
             ids = [id for (id,) in superpage['ids']]
             results = []
             for rec in E1('open-ils.supercat.record.object.retrieve', ids):
-                marc = unicode(rec['marc'], 'utf-8')
+                marc = rec['marc']
+                # In some institutions' installations, 'marc' is a string; in
+                # others it's unicode. Convert to unicode if necessary.
+                if not isinstance(marc, unicode):
+                    marc = unicode(marc, 'utf-8')
                 tree = M.marcxml_to_records(marc)[0]
                 results.append(tree)
             numhits = int(superpage['count'])
-    return results, numhits, bibid, bc
+    return results, numhits, bibid, barcode
 
 def bib_id_to_marcxml(bib_id):
     """
@@ -313,10 +319,10 @@
         return ('%sopac/en-CA'
                 '/skin/uwin/xml/rdetail.xml?r=%s&l=1&d=0' % (EG_BASE, bib_id))
 
-if False: # if USE_Z3950:
-    # only if we are using Z39.50 for catalogue search. Results including
-    # accented characters are often seriously messed up. (Try searching for
-    # "montreal").
+if USE_Z3950:
+    # only if we are using Z39.50 for catalogue search. Against our Conifer
+    # Z39.50 server, results including accented characters are often seriously
+    # messed up. (Try searching for "montreal").
     def get_better_copy_of_marc(marc_string):
         """
         This function takes a MARCXML record and returns either the same



More information about the open-ils-commits mailing list