From ef37ccd090ce9a49209e614773a2b4ef8078195b Mon Sep 17 00:00:00 2001 From: gfawcett Date: Fri, 3 Apr 2009 02:45:30 +0000 Subject: [PATCH] ugly-but-functional SIP patron-check, item-status-check and item checkout. Needs some configuring at the bottom of settings.py to get the SIP to work. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@252 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/TODO | 3 ++ conifer/custom/lib_integration.py | 34 ++++++++++++------ conifer/libsystems/sip/sipclient.py | 67 +++++++++++++++++++++++++++++++++-- conifer/settings.py | 19 ++++++++++ conifer/syrup/views.py | 5 ++- conifer/templates/phys/checkout.xhtml | 2 +- 6 files changed, 114 insertions(+), 16 deletions(-) diff --git a/conifer/TODO b/conifer/TODO index 3d86214..9230f0a 100644 --- a/conifer/TODO +++ b/conifer/TODO @@ -7,3 +7,6 @@ * Import of reserves data from Leddy voyager. Laurentian, others? * Generating barcodes in emails, printable screens? (3 of 9 enough?) + +* People should be able to register themselves into open courses. + That is, actually become a member of them. diff --git a/conifer/custom/lib_integration.py b/conifer/custom/lib_integration.py index 9dbce90..1f89406 100644 --- a/conifer/custom/lib_integration.py +++ b/conifer/custom/lib_integration.py @@ -1,5 +1,10 @@ # Our integration-point with back-end library systems. +# This is a work in progress. I'm trying to separate out the actual +# protocol handlers (in libsystems) from the configuration decicions +# (in settings.py), and use this as sort of a merge-point between +# those two decisions. + # TODO: write some documentation about the lib_integration interface. # Our example configuration: @@ -7,20 +12,27 @@ # SIP for patron and item_info, and for item checkout and checkin, # OpenSRF for extended item info. -from conifer.libsystems.sip import sipclient +from django.conf import settings +#LIBINT = settings.LIBRARY_INTEGRATION # more on this later. + +from conifer.libsystems.sip.sipclient import SIP + + +@SIP +def patron_info(conn, barcode): + return conn.patron_info(barcode) +@SIP +def item_status(conn, barcode): + return conn.item_info(barcode) -def patron_info(barcode): - conn = sipclient.sip_connection() - resp = sipclient.sip_connection().patron_info(barcode) - conn.close() - return resp +@SIP +def checkout(conn, patron_barcode, item_barcode): + return conn.checkout(patron_barcode, item_barcode, '') -def item_info(barcode): - conn = sipclient.sip_connection() - resp = conn.item_info(barcode) - conn.close() - return resp +@SIP +def checkin(conn, item_barcode): + return conn.checkin(item_barcode, institution='', location='') diff --git a/conifer/libsystems/sip/sipclient.py b/conifer/libsystems/sip/sipclient.py index 5a84383..a7cf93e 100644 --- a/conifer/libsystems/sip/sipclient.py +++ b/conifer/libsystems/sip/sipclient.py @@ -26,7 +26,7 @@ import sys from datetime import datetime import re -DEBUG = False +DEBUG = True # ------------------------------------------------------------ # helper functions @@ -259,6 +259,10 @@ MESSAGES = { fld_localtime, charfield('protocol', default='2.00'), fld_INST_ID, + optfield('patron_id', FID_PATRON_ID), + optfield('item_id', FID_ITEM_ID), + optfield('terminal_pwd', FID_TERMINAL_PWD), + optfield('instname', FID_LIBRARY_NAME), field('supported', FID_SUPPORTED_MSGS), optfield('ttylocn', FID_TERMINAL_LOCN), @@ -328,6 +332,28 @@ MESSAGES = { ofld_print_line, ofld_screen_msg), + CHECKOUT: message( + CHECKOUT, + yn('renewals_OK'), + yn('no_block'), + fld_localtime, + fld_localtime, + field('inst', FID_INST_ID), + field('patron', FID_PATRON_ID), + field('item', FID_ITEM_ID), + ), + + CHECKIN: message( + CHECKIN, + yn('is_retry'), + fld_localtime, + fld_localtime, + field('item', FID_ITEM_ID), + field('location', FID_CURRENT_LOCN), + field('inst', FID_INST_ID), + ofld_TERMINAL_PWD, + ), + ITEM_INFORMATION : message( ITEM_INFORMATION, fld_localtime, @@ -412,6 +438,21 @@ class SipClient(object): 'startitem':1, 'enditem':2}) return msg + def checkout(self, patron, item, inst=''): + msg = self.send(CHECKOUT, RAW, # fixme + {'patron':patron, + 'inst': inst, + 'item':item}) + return msg + + def checkin(self, item, institution='', location=''): + msg = self.send(CHECKIN, RAW, # fixme + {'inst': institution, + 'location':location, + 'is_retry':False, + 'item':item}) + return msg + def item_info(self, barcode): msg = self.send(ITEM_INFORMATION, ITEM_INFO_RESP, {'item':barcode}) @@ -446,6 +487,15 @@ try: raise 'SipLoginError' return sip + # decorator + def SIP(fn): + def f(*args, **kwargs): + conn = sip_connection() + resp = fn(conn, *args, **kwargs) + conn.close() + return resp + return f + except ImportError: pass @@ -456,7 +506,7 @@ except ImportError: if __name__ == '__main__': from pprint import pprint - sip = SipClient('localhost', 6001) + sip = SipClient('home', 6001) resp = sip.login(uid='scclient', pwd='clientpwd', locn='The basement') pprint(resp) @@ -473,9 +523,20 @@ if __name__ == '__main__': result = sip.send(ITEM_INFORMATION, ITEM_INFO_RESP, {'item':item}) print '%-12s: %s' % (item, result['title'] or '????') - + print sip.send(CHECKOUT, RAW, + {'patron':'scclient-2', + 'inst': 'UWOLS', + 'item':item}) + print '\n' * 5 pprint(sip.send(END_PATRON_SESSION, END_SESSION_RESP, {'patron':'scclient', 'inst':'UWOLS'})) + +#checked out a book! +#"{'raw': '121NNY20090402 220912AOconifer|AA21862000380830|AB31862017120995|AJNo great mischief|AH2009-07-31 00:00:00|CK001|\\r'}" + +#checked it back in: +#"{'raw': '101YNN20090402 222519AO|AB31862017120995|AQLeddy Library|AJNo great mischief|AA21862000380830|CK001|\\r'}" + diff --git a/conifer/settings.py b/conifer/settings.py index e20c116..e3816e5 100644 --- a/conifer/settings.py +++ b/conifer/settings.py @@ -106,8 +106,27 @@ AUTHENTICATION_BACKENDS = [ 'django.contrib.auth.backends.ModelBackend', ] + +# more on this later. +LIBRARY_INTEGRATION = { + 'patron_info': 'SIP', + 'item_status': 'SIP', + 'item_info' : 'OpenSRF', + 'catalogue' : 'Z39.50', +} + EVERGREEN_XMLRPC_SERVER = None # evergreen host, for auth, e.g. '192.168.1.10' if EVERGREEN_XMLRPC_SERVER: AUTHENTICATION_BACKENDS.append( 'conifer.custom.auth_evergreen.EvergreenAuthBackend') + +# stuff that I really ought not check into svn... +#SIP_HOST = ('hostname', 9999) +#SIP_CREDENTIALS = ('userid', 'password', 'location') + +try: + # Graham has this right now; it's not official Syrup. Nothing to see here. + from private_local_settings import SIP_HOST, SIP_CREDENTIALS +except: + pass diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index e47e1f9..3102082 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -1241,14 +1241,17 @@ def phys_checkout(request): # also, make sure the barcode actually matches with a # known barcode in Syrup. We only checkout what we know # about. - msg = lib_integration.item_info(item) + msg = lib_integration.item_status(item) item_descrip = '%s — %s' % ( msg['title'], msg['status']) # do the checkout + msg = lib_integration.checkout(patron, item) + return g.render('phys/checkout.xhtml', step=3, patron=patron, item=item, patron_descrip=post('patron_descrip'), + checkout_result=msg['raw'], item_descrip=item_descrip) elif post('step') == '3': # continue after checkout. Go to 'checkout another item'. diff --git a/conifer/templates/phys/checkout.xhtml b/conifer/templates/phys/checkout.xhtml index 737102b..d73805f 100644 --- a/conifer/templates/phys/checkout.xhtml +++ b/conifer/templates/phys/checkout.xhtml @@ -42,7 +42,7 @@ title = _('Patron Checkout of Item') - Success: Item Checked Out (FOR PRETEND! Not doing checkout yet). + ${checkout_result} -- 2.11.0