OpenSRF lookup integrated, added slightly different
authorArt Rhyno <art632000@yahoo.ca>
Thu, 23 Jun 2011 19:45:17 +0000 (15:45 -0400)
committerArt Rhyno <art632000@yahoo.ca>
Thu, 23 Jun 2011 19:45:17 +0000 (15:45 -0400)
scoping than LDAP.

Signed-off-by: Art Rhyno <art632000@yahoo.ca>
conifer/integration/evergreen_example.py [new file with mode: 0644]
conifer/libsystems/evergreen/opensrf.py
conifer/local_settings.py.example
conifer/static/fuzzyFinder.js
conifer/syrup/views/admin.py
conifer/syrup/views/sites.py
conifer/templates/admin/staff_add.xhtml
conifer/templates/edit_site_permissions.xhtml

diff --git a/conifer/integration/evergreen_example.py b/conifer/integration/evergreen_example.py
new file mode 100644 (file)
index 0000000..a050565
--- /dev/null
@@ -0,0 +1,60 @@
+from datetime           import date
+from evergreen_site     import EvergreenIntegration
+import csv
+import subprocess
+from django.conf                          import settings
+from urllib2 import urlopen
+from django.utils import simplejson
+from conifer.libsystems.evergreen import opensrf
+
+
+class EvergreenExampleIntegration(EvergreenIntegration):
+
+    OSRF_CAT_SEARCH_ORG_UNIT = 28
+    
+    OPAC_LANG = 'en-US'
+    OPAC_SKIN = 'default'
+
+    RESERVES_DESK_NAME = 'Reserves'
+    SITE_DEFAULT_ACCESS_LEVEL = 'RESTR'
+
+    def external_person_lookup(self, userid):
+        """
+        Given a userid, return either None (if the user cannot be found),
+        or a dictionary representing the user. The dictionary must contain
+        the keys ('given_name', 'surname') and should contain 'email' if
+        an email address is known, and 'patron_id' if a library-system ID
+        is known.
+        """
+        return opensrf.ils_patron_details(userid)
+
+
+    def fuzzy_person_lookup(self, query, include_students=False, level='STAFF'):
+        patrons = []
+
+        if level == 'USERNAME':
+            patrons = opensrf.ils_patron_lookup(query,False,True,True)
+        elif level == 'EVERYONE':
+            patrons = opensrf.ils_patron_lookup(query,False,False,True)
+        else:
+            patrons = opensrf.ils_patron_lookup(query)
+        
+        return patrons
+
+    #---------------------------------------------------------------------------
+    # copyright/permissions
+
+    def download_declaration(self):
+        """
+        Returns a string. The declaration to which students must agree when
+        downloading electronic documents. If not customized, a generic message
+        will be used.
+        """
+        # based on U. of Windsor
+        return ("I warrant that I am a student of this university "
+                "enrolled in a course of instruction. By pressing the "
+                "'Request' button below, I am requesting a digital copy of a "
+                "reserve reading for research, private study, review or criticism "
+                "and that I will not use the copy for any other purpose, nor "
+                "will I transmit the copy to any third party.")
+
index 83207e3..a6a29bf 100644 (file)
@@ -112,6 +112,50 @@ def ils_item_info(barcode):
 
     return None, None, None
 
+def ils_patron_details(usrname):
+    dir_entry = {}
+
+    try:
+        authtoken = auth_token(settings.OPENSRF_STAFF_USERID, 
+            settings.OPENSRF_STAFF_PW,
+            settings.OPENSRF_STAFF_WORKSTATION)
+
+        if auth_token:
+            patrons = []
+            req = request('open-ils.actor',
+                'open-ils.actor.patron.search.advanced',
+                authtoken, {'usrname':{'value':usrname.strip(),'group':0}})
+            patron_info = req.send()
+            if patron_info:
+                patrons = patron_info
+            for patron in patrons[0:1]:
+                req = request('open-ils.actor',
+                    'open-ils.actor.user.fleshed.retrieve',
+                    authtoken, patron,
+                    ["first_given_name","family_name","email","cards"])
+                patron_info = req.send()
+                if patron_info:
+                    dir_entry['given_name'] = patron_info.first_given_name()
+                    dir_entry['surname'] = patron_info.family_name()
+                    dir_entry['email'] = patron_info.email()
+
+                    cards = patron_info.cards()
+                    if cards:
+                        barcode = None
+                        for card in cards:
+                            barcode = card.barcode()
+                            dir_entry['barcode'] = barcode
+                        
+            #clean up session
+            session_cleanup(authtoken)
+    except:
+            print "item update problem"
+            print "*** print_exc:"
+            traceback.print_exc()
+            pass          # fail silently in production
+
+    return dir_entry
+
 def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False):
     """
     This is the barebones of a fuzzy lookup using opensrf
@@ -148,7 +192,7 @@ def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False):
     if not is_barcode and is_number(name):
         return out
     is_email = False
-    if name.find('@') > 0:
+    if not is_usrname and name.find('@') > 0:
         is_email = True
 
     try:
@@ -182,6 +226,13 @@ def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False):
                         'open-ils.actor.patron.search.advanced',
                         authtoken, {'card':{'value':name.strip(),'group':3}})
                     patrons = req.send()
+            elif is_usrname:
+                    req = request('open-ils.actor',
+                        'open-ils.actor.patron.search.advanced',
+                        authtoken, {'usrname':{'value':name.strip(),'group':0}})
+                    patron_info = req.send()
+                    if patron_info:
+                        patrons = patron_info
             elif is_staff:
                 patrons.extend(group_search(query,authtoken,patrons))
                 if (len(patrons) < RESULT_LIMIT and default_query):
@@ -216,9 +267,9 @@ def ils_patron_lookup(name, is_staff=True, is_usrname=False, is_everyone=False):
                         authtoken, patron,
                         ["first_given_name","family_name","email","usrname"])
                 patron_info = req.send()
-                display = ('%s %s. %s, '
-                    '%s. <%s>. [%s]') % (patron_info.first_given_name(),
-                    patron_info.family_name(), 'Test', 'FACULTY/STAFF',
+                display = ('%s %s, '
+                    '<%s>. [%s]') % (patron_info.first_given_name(),
+                    patron_info.family_name(), 
                     patron_info.email(), patron_info.usrname())
                 out.append((patron_info.usrname(), display))
                         
index 87b7c40..1f8d092 100644 (file)
@@ -69,7 +69,7 @@ Z3950_CONFIG     = ('zed.concat.ca', 210, 'OWA')  #OWA,OSUL,CONIFER
 # other late initializations. See the 'conifer.syrup.integration' module for
 # more information.
 
-#INTEGRATION_CLASS = 'conifer.integration.uwindsor.UWindsorIntegration'
+#INTEGRATION_CLASS = 'conifer.integration.evergreen_example.EvergreenExampleIntegration'
 #GATEWAY_SERVER = 'windsor.concat.ca'
 #GATEWAY_URL = 'osrf-gateway-v1'
 #OPENSRF_STAFF_USERID = 'staff@projectconifer.ca'
index f83a198..e39991b 100644 (file)
@@ -31,8 +31,12 @@ function fuzzyFinder(Search, Matches, EditPanel, ViewPanel, ViewName, Change, Ow
            
            here.waiting = true;
            $(Search).css({backgroundColor: 'yellow'}); // debugging
+        var search='';
+        var search_level = document.getElementById('search_level');
+        if (search_level)
+            search = search_level.value;
            $.post(ROOT + '/fuzzy_user_lookup', {'q': here.lastText, 
-                                                includeStudents: here.includeStudents},
+                                                includeStudents: here.includeStudents, level: search},
                   function(data) {
                       here.waiting = false;
                       here.lastPress = null;
index 457a8a4..993e775 100644 (file)
@@ -156,13 +156,18 @@ def admin_staff_add(request):
         return g.render('admin/staff_add.xhtml', **locals())
     else:
         userid = request.POST.get('userid','').strip()
+        print "userid", userid
         message_continue = True
 
         try:
             user = User.objects.get(username=userid)
         except User.DoesNotExist:
+            print "about to create"
             user = User.objects.create(username=userid)
+            print "created", user
+            print "1"
             user.maybe_decorate()
+            print "2"
 
         user.is_staff = True
         user.is_superuser = True # TODO: are we sure they should be superuser?
index 2f92ba2..ad342c8 100644 (file)
@@ -254,8 +254,9 @@ def site_join(request, site_id):
 @admin_only
 def site_fuzzy_user_lookup(request):
     query = request.REQUEST.get('q').lower().strip()
+    level = request.REQUEST.get('level').strip()
     include_students = (request.REQUEST.get('includeStudents') == 'true')
-    results = callhook('fuzzy_person_lookup', query, include_students) or []
+    results = callhook('fuzzy_person_lookup', query, include_students, level) or []
     limit = 10
     resp = {'results': results[:limit], 
             'notshown': max(0, len(results) - limit)}
index 3463456..2387059 100644 (file)
@@ -31,8 +31,15 @@ title = _('Add new staff user')
   </p>
   <div>
     <div id="fuzzyedit" style="display: block">
-      <div style="font-size: 80%; margin: 0.5em 0;">Type a partial name or userid into the box; then select one of the matches.</div>
+      <div style="font-size: 80%; margin: 0.5em 0;">For fuzzy matches, type a partial name or username into the box, then select one of the matches.</div>
       <input type="text" id="fuzzyinput" autocomplete="off" value=""/>
+        <span style="margin: 8px;">
+        <select id="search_level">
+        <option value="STAFF" selected="selected">Staff</option>
+        <option value="USERNAME">Username</option>
+        <option value="EVERYONE">Everyone</option>
+        </select>
+        </span>
       <div id="fuzzypanel">
       </div>
     </div>
@@ -49,4 +56,4 @@ title = _('Add new staff user')
   </div>
   <p><a href="../../">Go back</a></p>
 </body>
-</html>
\ No newline at end of file
+</html>
index 24edff7..5f2d461 100644 (file)
@@ -106,6 +106,13 @@ extgroups = site.group_set.filter(external_id__isnull=False).annotate(Count('mem
                        Type a partial name or userid into the box; then select one of the matches.
                      </div>
                      <input type="text" id="fuzzyinput" autocomplete="off" value=""/>
+                <span style="margin: 8px;">
+                <select id="search_level">
+                <option value="EVERYONE" selected="selected">Everyone</option>
+                <option value="STAFF">Staff</option>
+                <option value="USERNAME">Username</option>
+                </select>
+                </span>
                      <div id="fuzzypanel">
                      </div>
                    </div>