[open-ils-commits] r265 - in servres/trunk/conifer: . custom libsystems/evergreen libsystems/z3950 syrup (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Apr 4 13:24:00 EDT 2009


Author: gfawcett
Date: 2009-04-04 13:23:57 -0400 (Sat, 04 Apr 2009)
New Revision: 265

Modified:
   servres/trunk/conifer/TODO
   servres/trunk/conifer/custom/lib_integration.py
   servres/trunk/conifer/libsystems/evergreen/item_status.py
   servres/trunk/conifer/libsystems/z3950/marcxml.py
   servres/trunk/conifer/syrup/views.py
Log:
added lib_integration.cat_search as proper hook for z3950. Evergreen URLs are valid search queries.

    It's a hack, but if you paste an Evergreen "title details" URL
    into the catalogue search interface, it will fetch the correct
    MARCXML record and display the item. Currently hard-coded to the
    Conifer catalogue, will fix that.

Modified: servres/trunk/conifer/TODO
===================================================================
--- servres/trunk/conifer/TODO	2009-04-04 17:14:16 UTC (rev 264)
+++ servres/trunk/conifer/TODO	2009-04-04 17:23:57 UTC (rev 265)
@@ -15,6 +15,8 @@
 
 * testing on broken browsers (you know who you are)
 
+* the code is littered with 'dwarf' refrences. Factor out into config.
+
 MAYBE:
 
 * Generating barcodes in emails, printable screens? (3 of 9 enough?)

Modified: servres/trunk/conifer/custom/lib_integration.py
===================================================================
--- servres/trunk/conifer/custom/lib_integration.py	2009-04-04 17:14:16 UTC (rev 264)
+++ servres/trunk/conifer/custom/lib_integration.py	2009-04-04 17:23:57 UTC (rev 265)
@@ -37,6 +37,8 @@
 
 from conifer.libsystems.evergreen import item_status as I
 from conifer.libsystems.sip.sipclient import SIP
+from conifer.libsystems.z3950 import yaz_search
+from conifer.libsystems.z3950.marcxml import marcxml_to_dictionary
 
 
 @SIP
@@ -67,3 +69,14 @@
 @caching('bimx', timeout=3600)
 def bib_id_to_marcxml(bib_id):
     return I.bib_id_to_marcxml(bib_id)
+
+
+def cat_search(query, start=1, limit=10):
+    # this is a total hack for conifer. If the query is a Conifer
+    # title-detail URL, then return just that one item.
+    if query.startswith('http://dwarf'):
+        results = [marcxml_to_dictionary(I.url_to_marcxml(query))]
+    else:
+        cat_host, cat_db = ('dwarf.cs.uoguelph.ca:2210', 'conifer')
+        results = yaz_search.search(cat_host, cat_db, query, start, limit)
+    return results

Modified: servres/trunk/conifer/libsystems/evergreen/item_status.py
===================================================================
--- servres/trunk/conifer/libsystems/evergreen/item_status.py	2009-04-04 17:14:16 UTC (rev 264)
+++ servres/trunk/conifer/libsystems/evergreen/item_status.py	2009-04-04 17:23:57 UTC (rev 265)
@@ -1,4 +1,6 @@
 from support import ER, E1
+import re
+import urllib2
 
 def barcode_to_bib_id(barcode):
     bib_id = (E1('open-ils.search.bib_id.by_barcode', barcode))
@@ -10,6 +12,18 @@
 def bib_id_to_marcxml(bib_id):
     return E1('open-ils.supercat.record.marcxml.retrieve', bib_id)
 
+def url_to_marcxml(url):
+    # this is a hack. Given a opac Title Details url, return marcxml.
+    if url.startswith('http://dwarf.cs.uoguelph.ca'):
+        m = re.match(r'.*r=(\d+).*', url)
+        item_id = m and m.group(1) or None
+        if item_id:
+            marc_url = ("http://dwarf.cs.uoguelph.ca/opac/extras"
+                        "/supercat/retrieve/marcxml/record/" + item_id)
+        xml = urllib2.urlopen(marc_url).read()
+        return xml
+
 if __name__ == '__main__':
-    from pprint import pprint
-    print bib_id_to_marcxml(barcode_to_bib_id(31862016799294))
+#     from pprint import pprint
+#     print bib_id_to_marcxml(barcode_to_bib_id(31862016799294))
+    print url_to_marcxml('http://dwarf.cs.uoguelph.ca/opac/en-US/skin/default/xml/rdetail.xml?r=1082665&t=dylan%20thomas%20ralph&tp=keyword&d=0&hc=14&rt=keyword')

Modified: servres/trunk/conifer/libsystems/z3950/marcxml.py
===================================================================
--- servres/trunk/conifer/libsystems/z3950/marcxml.py	2009-04-04 17:14:16 UTC (rev 264)
+++ servres/trunk/conifer/libsystems/z3950/marcxml.py	2009-04-04 17:23:57 UTC (rev 265)
@@ -5,6 +5,9 @@
 
 def marcxml_to_dictionary(rec):
     tree = ElementTree.fromstring(rec)
+    if tree.tag == '{http://www.loc.gov/MARC21/slim}collection':
+        # thenwe only look at the first record.
+        tree = tree.find('{http://www.loc.gov/MARC21/slim}record')
     dct = {}
     for df in tree.findall('{http://www.loc.gov/MARC21/slim}datafield'):
         t = df.attrib['tag']

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-04-04 17:14:16 UTC (rev 264)
+++ servres/trunk/conifer/syrup/views.py	2009-04-04 17:23:57 UTC (rev 265)
@@ -729,16 +729,18 @@
 def item_add_cat_search(request, course_id, item_id):
     if request.method != 'POST':
         return g.render('item_add_cat_search.xhtml', results=[], query='@and dylan thomas')
-    query = request.POST.get('query','').strip()
+
+    # POST handler
+    query     = request.POST.get('query','').strip()
     _pickitem = request.POST.get('pickitem', '').strip()
     if not _pickitem:
+        # process the query.
         assert query, 'must provide a query.'
-        from conifer.libsystems.z3950 import yaz_search
-        host, db, query = ('dwarf.cs.uoguelph.ca:2210', 'conifer', query)
-        #host, db = ('z3950.loc.gov:7090', 'VOYAGER')
-        results = yaz_search.search(host, db, query)
-        return g.render('item_add_cat_search.xhtml', results=results, query=query)
+        results = lib_integration.cat_search(query)
+        return g.render('item_add_cat_search.xhtml', 
+                        results=results, query=query)
     else:
+        # User has selected an item; add it to course site.
         #fixme, this block copied from item_add. refactor.
         parent_item_id = item_id
         if parent_item_id=='0':
@@ -767,11 +769,13 @@
         item.save()
         return HttpResponseRedirect('../../../%d/' % item.id)
 
+#------------------------------------------------------------
+
+#this is used in item_edit.
 metadata_formset_class = modelformset_factory(models.Metadata, 
                                               fields=['name','value'], 
                                               extra=3, can_delete=True)
 
-
 @instructors_only
 def item_edit(request, course_id, item_id):
     course = get_object_or_404(models.Course, pk=course_id)



More information about the open-ils-commits mailing list