From: Art Rhyno Date: Thu, 23 Jun 2011 04:50:26 +0000 (-0400) Subject: Added the start of a fuzzy lookup for opensrf, X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=be502dbbe6fd810cc83f3101057884db90b43011;p=Syrup.git Added the start of a fuzzy lookup for opensrf, need to bring forward groups for filtering but otherwise looks good. Signed-off-by: Art Rhyno --- diff --git a/conifer/libsystems/evergreen/opensrf.py b/conifer/libsystems/evergreen/opensrf.py index 31c245d..e1751d3 100644 --- a/conifer/libsystems/evergreen/opensrf.py +++ b/conifer/libsystems/evergreen/opensrf.py @@ -112,6 +112,106 @@ def ils_item_info(barcode): return None, None, None +def ils_patron_lookup(patron): + """ + This is the barebones of a fuzzy lookup using opensrf + """ + def is_number(s): + try: + float(s) + return True + except ValueError: + return False + + out = [] + if len(patron) < settings.MIN_QUERY_LENGTH: + return out + is_barcode = re.search('\d{14}', patron) + if not is_barcode and is_number(patron): + return out + is_email = False + if patron.find('@') > 0: + is_email = True + + try: + query = None + query1 = None + query2 = None + incoming = None + + if not is_barcode: + incoming = patron.split() + query1 = incoming[0] + + if len(incoming) > 1: + #in case wild card searching can be used + query2 = '%s' % incoming[1].strip() + query = {'first_given_name':{'value':query1,'group':0}, + 'family_name':{'value':query2,'group':0}} + else: + query1 = '%s' % query1 + query = {'first_given_name':{'value':query1,'group':0}} + + authtoken = auth_token(settings.OPENSRF_STAFF_USERID, + settings.OPENSRF_STAFF_PW, + settings.OPENSRF_STAFF_WORKSTATION) + + if auth_token: + patron_info = [] + if not is_barcode and not is_email: + req = request('open-ils.actor', + 'open-ils.actor.patron.search.advanced', + authtoken, query) + patron_info = req.send() + if not patron_info and len(incoming) == 1: + req = request('open-ils.actor', + 'open-ils.actor.patron.search.advanced', + authtoken, {'family_name':{'value':query1,'group':0},'profile':{'value':'11','group':0}}) + patron_info = req.send() + if is_email: + req = request('open-ils.actor', + 'open-ils.actor.patron.search.advanced', + authtoken, {'email':{'value':query1,'group':0}}) + patron_info = req.send() + if is_barcode: + req = request('open-ils.actor', + 'open-ils.actor.patron.search.advanced', + authtoken, {'card':{'value':patron.strip(),'group':3}}) + patron_info = req.send() + + if patron_info: + cnt = 0 + for patron in patron_info: + req = request('open-ils.actor', + 'open-ils.actor.user.fleshed.retrieve', + authtoken, patron, + ["profile"]) + ind_info = req.send() + profile = ind_info.profile() + profile_id = profile.id() + + if int(profile_id) in settings.OPENSRF_PERMIT_GRPS: + cnt+=1 + display = ('%s %s. %s, ' + '%s. <%s>. [%s]') % (ind_info.first_given_name(), + ind_info.family_name(), 'Test', 'FACULTY/STAFF', + ind_info.email(), ind_info.usrname()) + out.append((ind_info.usrname(), display)) + if cnt == 5: + return out + + #clean up session + session_cleanup(authtoken) + except: + print "item update problem" + print "*** print_exc:" + traceback.print_exc() + pass # fail silently in production + return out + + return out + + def ils_item_update(barcode, callno, modifier, location): item_changed = False callno_changed = False diff --git a/conifer/local_settings.py.example b/conifer/local_settings.py.example index d6f2421..87b7c40 100644 --- a/conifer/local_settings.py.example +++ b/conifer/local_settings.py.example @@ -55,6 +55,7 @@ RESERVES_DESK_NAME = 'Leddy: Course Reserves - Main Bldng - 1st Flr - Reserve Co SYRUP_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S' SYRUP_DUE_FORMAT = '%b %d %Y, %r' ATTACHMENT_REGEXP ='\w*DVD\s?|\w*CD\s?|\w[Gg]uide\s?|\w[Bb]ooklet\s?|\w*CD\-ROM\s?' +MIN_QUERY_LENGTH = 3 # Note, in the Evergreen integration, commenting out Z3950_CONFIG or setting it # equal to None will result in OpenSRF being used for catalogue search instead @@ -75,3 +76,4 @@ Z3950_CONFIG = ('zed.concat.ca', 210, 'OWA') #OWA,OSUL,CONIFER #OPENSRF_STAFF_PW = 'mypassword' #OPENSRF_STAFF_ORG = 'OWA' #OPENSRF_STAFF_WORKSTATION = 'OWA-syrup-test' +#OPENSRF_PERMIT_GRPS = [3,4,5,11,12]