@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:
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):
"""
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))
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)
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 "
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
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',
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
--- /dev/null
+# 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)
from conifer.libsystems.evergreen.support import initialize, E1
from conifer.libsystems.evergreen.opensrf import *
-@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)."""
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,
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:
barcode = bc,
circ_modifier = eg_modifier,
circ_desk = eg_desk,
- orig_callno = callno,
+ orig_callno = eg_callno,
marcxml=raw_pickitem,
**dct)
item.save()