[open-ils-commits] r1279 - in servres/trunk/conifer: integration libsystems/evergreen syrup/views (artunit)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Mar 23 15:13:29 EDT 2011


Author: artunit
Date: 2011-03-23 15:13:24 -0400 (Wed, 23 Mar 2011)
New Revision: 1279

Added:
   servres/trunk/conifer/libsystems/evergreen/startup.py
Modified:
   servres/trunk/conifer/integration/uwindsor.py
   servres/trunk/conifer/libsystems/evergreen/opensrf.py
   servres/trunk/conifer/syrup/views/items.py
Log:
fm_IDL.xml update now done at startup, all items update tasks use evergreen python bindings proper

Modified: servres/trunk/conifer/integration/uwindsor.py
===================================================================
--- servres/trunk/conifer/integration/uwindsor.py	2011-03-23 03:20:57 UTC (rev 1278)
+++ servres/trunk/conifer/integration/uwindsor.py	2011-03-23 19:13:24 UTC (rev 1279)
@@ -89,6 +89,12 @@
 
 @memoize(timeout=CACHE_TIME)
 def _item_status(bib_id):
+    """
+	At this point, status information does not require the opensrf 
+	bindings, I am not sure there is a use case where an evergreen
+	site would not have access to these but will leave for now
+	since there are no hardcoded references
+    """
             
     if bib_id:
         try:
@@ -229,6 +235,7 @@
 
 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
     if query.startswith(EG_BASE):
@@ -301,6 +308,7 @@
     """
     Given a bib ID, return either a URL for examining the bib record, or None.
     """
+    # TODO: move this to local_settings
     if bib_id:
         return ('%sopac/en-CA'
                 '/skin/uwin/xml/rdetail.xml?r=%s&l=1&d=0' % (EG_BASE, bib_id))
@@ -337,6 +345,7 @@
     856$u form an associative array, where $9 holds the institution
     codes and $u holds the URLs.
     """
+    # TODO: move this to local_settings
     LIBCODE = 'OWA'             # Leddy
     try:
         dct   = M.marcxml_to_dictionary(marc_string)
@@ -447,6 +456,7 @@
     will be used.
     """
     # as per Joan Dalton, 2010-12-21.
+    # TODO: move this to local_settings
     return ("I warrant that I am a student of the University of Windsor "
             "enrolled in a course of instruction. By pressing the "
             "'Request' button below, I am requesting a digital copy of a "

Modified: servres/trunk/conifer/libsystems/evergreen/opensrf.py
===================================================================
--- servres/trunk/conifer/libsystems/evergreen/opensrf.py	2011-03-23 03:20:57 UTC (rev 1278)
+++ servres/trunk/conifer/libsystems/evergreen/opensrf.py	2011-03-23 19:13:24 UTC (rev 1279)
@@ -74,39 +74,6 @@
         
     return True
 
-def load_idl():
-    """
-    Loads the fieldmapper IDL, registering class hints for the defined objects
-
-    We use a temporary file to store the IDL each time load_idl()
-    is invoked to ensure that the IDL is in sync with the target
-    server. One could a HEAD request to do some smarter caching,
-    perhaps.
-    """
-    
-    parser = oils.utils.idl.IDLParser()
-    idlfile = tempfile.TemporaryFile()
-
-    # Get the fm_IDL.xml file from the server
-    try:
-        idl = urllib2.urlopen('%s://%s/%s' % 
-            (settings.OSRF_HTTP, settings.EVERGREEN_GATEWAY_SERVER, settings.IDL_URL)
-        )
-        idlfile.write(idl.read())
-        # rewind to the beginning of the file
-        idlfile.seek(0)
-
-    #no pass on these, updates are too critical to ever be out of sync
-    except urllib2.URLError, exc:
-        print("Could not open URL to read IDL: %s", exc.code)
-
-    except IOError, exc:
-        print("Could not write IDL to file: %s", exc.code)
-
-    # parse the IDL
-    parser.set_IDL(idlfile)
-    parser.parse_IDL()
-
 def request(service, method, *args):
     """
     Make a JSON request to the OpenSRF gateway
@@ -121,17 +88,38 @@
     req.setPath(settings.GATEWAY_URL)
     return req
 
+def ils_item_info(barcode):
+    """
+    We store some item information with syrup record 
+    """
+    try:
+    	req = request('open-ils.search',
+		'open-ils.search.asset.copy.fleshed2.find_by_barcode',
+		barcode)
+    	barcode_copy = req.send()
+        # print "debug", osrf.json.debug_net_object(barcode_copy)
+
+    	if barcode_copy:
+        	req = request('open-ils.search', 
+			'open-ils.search.asset.call_number.retrieve',
+                	barcode_copy.call_number())
+   
+        	call_num = req.send()
+		if call_num:
+			return barcode_copy.circ_modifier(), barcode_copy.location().id(), call_num.label()
+    except:
+            print "problem retrieving item info"
+            print "*** print_exc:"
+            traceback.print_exc()
+            pass          # fail silently in production
+
+    return None, None, None
+
 def ils_item_update(barcode, callno, modifier, location):
     try:
 	item_changed = False
 	callno_changed = False
 
-    	# Set the host for our requests
-    	osrf.gateway.GatewayRequest.setDefaultHost(settings.EVERGREEN_GATEWAY_SERVER)
-
-    	# Pull all of our object definitions together
-    	load_idl()
-
     	# We get our copy object
     	req = request('open-ils.search', 
 		'open-ils.search.asset.copy.fleshed2.find_by_barcode', 
@@ -139,7 +127,7 @@
     	barcode_copy = req.send()
 
 	# are there changes?
-	if barcode_copy.location().id != location or barcode_copy.circ_modifier != modifier:
+	if barcode_copy.location().id != location or barcode_copy.circ_modifier() != modifier:
 		item_changed = True 
 
     	# And our call number object

Added: servres/trunk/conifer/libsystems/evergreen/startup.py
===================================================================
--- servres/trunk/conifer/libsystems/evergreen/startup.py	                        (rev 0)
+++ servres/trunk/conifer/libsystems/evergreen/startup.py	2011-03-23 19:13:24 UTC (rev 1279)
@@ -0,0 +1,58 @@
+# startup ils tasks go here
+
+import os
+
+import oils.event
+import oils.utils.idl
+import oils.utils.utils
+import osrf.gateway
+import osrf.json
+import sys
+import tempfile
+import urllib2
+
+def load_idl(osrf_http, gateway_server, idl_url):
+    """
+    Loads the fieldmapper IDL, registering class hints for the defined objects
+
+    We use a temporary file to store the IDL each time load_idl()
+    is invoked to ensure that the IDL is in sync with the target
+    server. One could a HEAD request to do some smarter caching,
+    perhaps.
+    """
+    
+    parser = oils.utils.idl.IDLParser()
+    idlfile = tempfile.TemporaryFile()
+
+    # Get the fm_IDL.xml file from the server
+    try:
+	print '%s://%s/%s' % (osrf_http, gateway_server, idl_url)
+        idl = urllib2.urlopen('%s://%s/%s' % 
+            (osrf_http, gateway_server, idl_url)
+        )
+        idlfile.write(idl.read())
+        # rewind to the beginning of the file
+        idlfile.seek(0)
+
+    #no pass on these, updates are too critical to ever be out of sync
+    except urllib2.URLError, exc:
+        print("Could not open URL to read IDL: %s", exc.code)
+
+    except IOError, exc:
+        print("Could not write IDL to file: %s", exc.code)
+
+    # parse the IDL
+    parser.set_IDL(idlfile)
+    parser.parse_IDL()
+
+def ils_startup(EVERGREEN_GATEWAY_SERVER, OSRF_HTTP, IDL_URL):
+    """
+    Put any housekeeping for ILS interactions here, the definitions come from
+    local_settings in the call itself rather than an import
+    """
+    	
+    # Set the host for our requests
+    osrf.gateway.GatewayRequest.setDefaultHost(EVERGREEN_GATEWAY_SERVER)
+
+    # Pull all of our object definitions together
+    load_idl(OSRF_HTTP, EVERGREEN_GATEWAY_SERVER, IDL_URL)

Modified: servres/trunk/conifer/syrup/views/items.py
===================================================================
--- servres/trunk/conifer/syrup/views/items.py	2011-03-23 03:20:57 UTC (rev 1278)
+++ servres/trunk/conifer/syrup/views/items.py	2011-03-23 19:13:24 UTC (rev 1279)
@@ -9,65 +9,6 @@
 from conifer.libsystems.evergreen.support import initialize, E1
 from conifer.libsystems.evergreen.opensrf     import *
 
- at instructors_only
-def item_ils_update_test(request):
-    """Update item in ILS""" 
-    # this works in my tests, need to try more variations
-    # disable in production for now
-    circ_mods = settings.EVERGREEN_CIRC_MODS
-    # for circ_modifier in circ_mods:
-
-    token = auth_token(settings.OPENSRF_STAFF_USERID, settings.OPENSRF_STAFF_PW,
-	settings.OPENSRF_STAFF_ORG, settings.OPENSRF_STAFF_WORKSTATION)
-    print "token", token
-    null = None
-    true = True
-    false = False
-    # barcode will come from form
-    barcode = "31862005297755"
-    barcode_copy = E1(settings.OPENSRF_CN_BARCODE, token, barcode);
-    copy = None
-    if barcode_copy:
-	volumeinfo = barcode_copy.get("volume")
-	if volumeinfo:
-		volume = volumeinfo['__p']
-		print "volume", volume
-		print "call", volume[7]
-		volume[0] = []
-		volume[5] = 1
-		volume[7] = "QA76.74.M63 B45 2010"
-		volume[13] = None
-		volume.append(None)
-		volume.append('1')
-		print "WOULD UPDATE", volume
-		# updaterec = E1("open-ils.actor.user.perm.check.multi_org", token, 104965, [109], ["UPDATE_VOLUME"])
-    		# print "updaterec", updaterec
-		updaterec = E1(settings.OPENSRF_VOLUME_UPDATE, token, [{"__c":"acn","__p":volume}], false, {"auto_merge_vols":false})
-    		print "updaterec", updaterec
-    session_cleanup(token)
-    return simple_message(_('testing.'), _('testing.'))
-    if barcode_copy:
-	copy = barcode_copy.get("copy")
-	if copy:
-		print "copy", copy
-		detailid = copy['__p'][21]
-		details = E1(settings.OPENSRF_FLESHEDCOPY_CALL, [detailid])
-		print "details", details
-		location = details[0]['__p'][23]['__p'][3]
-		# details[0]['__p'][6] = "RSV1"
-		details[0]['__p'][6] = circ_mods[0]
-		print "location", location
-		details[0]['__p'][23] = location
-		details[0]['__p'][23] = settings.EVERGREEN_RSV_DESK
-		#the joy of testing, these are in the fm_IDL.xml for RC but not production (total circ and holds)
-		details[0]['__p'].append(None)
-		details[0]['__p'].append('1')
-		print "WOULD UPDATE", details
-		# updaterec = E1(settings.OPENSRF_BATCH_UPDATE, token, details,true)
-    		# print "updaterec", updaterec
-    session_cleanup(token)
-    return simple_message(_('testing.'), _('testing.'))
-
 @members_only
 def item_detail(request, site_id, item_id):
     """Display an item (however that makes sense).""" 
@@ -357,33 +298,18 @@
 
 	bibid = bib_id=request.POST.get('bibid')
 	bc = None
-	callno = None
+
+	#TODO: Leddy combines notion of desk and location for reserves, but it
+	# is confusing in terms of the catalogue, need to make this consistent
+	eg_callno = None
 	eg_modifier = None
-	eg_desk = None
+	eg_location = None
 
 	#TODO: use python bindings for these interactions
 	bar_num=request.POST.get('bc')
 	if bar_num and settings.OPENSRF_STAFF_USERID:
 		bc = bar_num
-    		token = auth_token(settings.OPENSRF_STAFF_USERID, settings.OPENSRF_STAFF_PW,
-        		settings.OPENSRF_STAFF_ORG, settings.OPENSRF_STAFF_WORKSTATION)
-    		barcode_copy = E1(settings.OPENSRF_CN_BARCODE, token, bc);
-    		if barcode_copy:
-        		volumeinfo = barcode_copy.get("volume")
-        		copyinfo = barcode_copy.get("copy")
-        		if volumeinfo:
-                		volume = volumeinfo['__p']
-				if volume:
-					callno = volume[7]
-			if copyinfo:
-				detailid = copyinfo['__p'][21]
-                		details = E1(settings.OPENSRF_FLESHEDCOPY_CALL, [detailid])
-				if details:
-					eg_desk = details[0]['__p'][23]['__p'][3]
-					print "eg_desk", eg_desk
-					eg_modifier = details[0]['__p'][6]
-				
-    		session_cleanup(token)
+		eg_modifier, eg_location, eg_callno = ils_item_info(bc)
 
 	if bibid > 0:
         	item = site.item_set.create(parent_heading=parent_item,
@@ -394,8 +320,8 @@
                                     bib_id = bibid,
                                     barcode = bc,
                                     circ_modifier = eg_modifier,
-                                    circ_desk = eg_desk,
-                                    orig_callno = callno,
+                                    circ_desk = eg_location,
+                                    orig_callno = eg_callno,
                                     marcxml=raw_pickitem,
                                     **dct)
 	else:
@@ -407,7 +333,7 @@
                                     barcode = bc,
                                     circ_modifier = eg_modifier,
                                     circ_desk = eg_desk,
-                                    orig_callno = callno,
+                                    orig_callno = eg_callno,
                                     marcxml=raw_pickitem,
                                     **dct)
         item.save()



More information about the open-ils-commits mailing list