browsing z39.50 using paginator
authorartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 17 Mar 2009 13:16:45 +0000 (13:16 +0000)
committerartunit <artunit@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Tue, 17 Mar 2009 13:16:45 +0000 (13:16 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@193 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/views.py
conifer/templates/admin/index.xhtml
conifer/templates/paginate.xhtml
conifer/templates/zsearch_results.xhtml

index e392d9c..9816038 100644 (file)
@@ -811,24 +811,47 @@ def search(request, in_course=None):
 def zsearch(request):
     ''' 
     '''
-    if request.method == 'GET':
+        
+    if request.GET.get('page')==None:
+        print("nope")
+    page_num = int(request.GET.get('page', 1))
+    count = int(request.POST.get('count', 5))
+
+    if request.GET.get('page')==None and request.method == 'GET':
         targets_list = models.Target.objects.filter(active=True).order_by('name')
         targets_len = len(targets_list)
         return g.render('zsearch.xhtml', **locals())
     else:
-        start = int(request.POST.get('start', 1))
-        count = int(request.POST.get('count', 5))
-        search_target= models.Target.objects.get(name=request.POST['target'])
+            
+        target = request.GET.get('target')
+        if request.method == 'POST':
+            target = request.POST['target']
+        print("target is %s" % target)
+            
+        tquery = request.GET.get('query')
+        if request.method == 'POST':
+            tquery = request.POST['ztitle']
+        search_target= models.Target.objects.get(name=target)
         conn = zoom.Connection (search_target.host, search_target.port)
         conn.databaseName = search_target.db
         conn.preferredRecordSyntax = search_target.syntax
-        # query = zoom.Query ('CCL', '%s="%s"' % ('ti','1066 and all that'))
-        query = zoom.Query ('CCL', '%s="%s"' % ('ti',request.POST['ztitle']))
-        # print("connecting...")
+        query = zoom.Query ('CCL', '%s="%s"' % ('ti',tquery))
         res = conn.search (query)
+        print("results are %d" % len(res))
         collector = []
 
-        for r in res[start: start + count]:
+        '''
+        need to add some plumbing for scan if possible
+        suspect this is too much overhead, though it could just be
+        the target z39.50 server that is slow
+        '''
+        # we fudge this since it has more overhead 
+        start = (page_num - 1) * count
+        end = (page_num * count) + 1
+        for r in res[0: start]:
+                print("none")
+                collector.append ((None, None))
+        for r in res[start + 1: end]:
             if r.syntax <> 'USMARC':
                 collector.append ((None, 'Unsupported syntax: ' + r.syntax, None))
             else:
@@ -839,11 +862,11 @@ def zsearch(request):
                 # print marcdata
 
                 # Convert to MARCXML
-                marcxml = marcdata.toMARCXML()
-                print marcxml
+                marcxml = marcdata.toMARCXML()
+                print marcxml
 
                 # How to Remove non-ascii characters (in case this is a problem)
-                marcxmlascii = unicode(marcxml, 'ascii', 'ignore').encode('ascii')
+                #marcxmlascii = unicode(marcxml, 'ascii', 'ignore').encode('ascii')
                 
                 bibid = marcdata.fields[1][0]
                 title = " ".join ([v[1] for v in marcdata.fields [245][0][2]])
@@ -857,10 +880,19 @@ def zsearch(request):
                     title = t[0].xml_text_content()
                 '''
                 
-                collector.append ((bibid, title))
+                # collector.append ((bibid, title))
+                #this is not a good situation but will leave for now
+                collector.append ((bibid, unicode(title, 'ascii', 'ignore')))
+        if end < len(res):
+            for r in res[end + 1:len(res)]:
+                    print("end none")
+                    collector.append ((None, None))
         conn.close ()
         # print("done searching...")
+        paginator = Paginator(collector, count) 
 
+    print("page_num is %d" % page_num)
+    print("returning...")
     return g.render('zsearch_results.xhtml', **locals())
 
 
index 466f907..ebe9aa2 100644 (file)
@@ -17,7 +17,8 @@ title = _('Administrative Options')
     <li><a href="items/">Items</a></li>
     <li><a href="news/">News Items</a></li>
     <li><a href="targets/">Manage Z39.50 Targets</a></li>
-    <li><a href="targets/">Search Z39.50 Targets</a></li>
+    <!-- not sure if this is an admin option yet -->
+    <li><a href="../zsearch/">Search Z39.50 Targets</a></li>
   </ul>
 </body>
 </html>
index 4f29a33..2fe6e41 100644 (file)
@@ -2,7 +2,7 @@
       xmlns:py="http://genshi.edgewall.org/"
       xmlns:xi="http://www.w3.org/2001/XInclude"
       py:strip="">
-<div py:def="pagetable(paginator, count, pagerow, pagehead=None)"
+<div py:def="pagetable(paginator, count, pagerow, pagehead=None, query=None, target=None)"
      py:with="page = paginator.page(page_num)">
   <table class="pagetable" py:with="cls = cycle(('odd', 'even'))"> 
     <thead py:if="pagehead">
   </table>
   <div class="pagination_controls" py:if="paginator.num_pages > 1">
     <span py:if="page.has_previous()" class="prev">
-      <a href=".?page=${page.previous_page_number()}&amp;count=${count}">Previous</a>
+      <a href=".?page=${page.previous_page_number()}&amp;count=${count}&amp;query=${query}&amp;target=${target}">Previous</a>
     </span>
     <span class="nums">
       <span py:for="pp in range(1, 1+paginator.num_pages)">
        <a style="font-weight: ${pp == page_num and 'bold' or 'normal'}"
-          href=".?page=${pp}&amp;count=${count}">${pp}</a>
+          href=".?page=${pp}&amp;count=${count}&amp;query=${query}&amp;target=${target}">${pp}</a>
       </span>
     </span>
     <span py:if="page.has_next()" class="next">
-      <a href=".?page=${page.next_page_number()}&amp;count=${count}">Next</a>
+      <a href=".?page=${page.next_page_number()}&amp;count=${count}&amp;query=${query}&amp;target=${target}">Next</a>
     </span>
   </div>
 </div>
index 05aac02..dc269b6 100644 (file)
@@ -15,14 +15,22 @@ title_list = collector
   </script>
 </head>
 <body>
-    <h1>${title}</h1>
-    
+<!--
     <table py:if="title_list" width="100%">
     <tr py:for="item in title_list">
     <td>${item[0]}</td>
     <td>${item[1]}</td>
     </tr>
     </table>
+-->
+  <h1>${title}</h1>
+  <tr py:def="pageheader()">
+    <th>Name</th>
+  </tr>
+  <span py:def="pagerow(item)">
+    <td><a href="${item[0]}">${item[1]}</a></td>
+  </span>
+  ${pagetable(paginator, count, pagerow, pageheader, tquery, target)}
 
 </body>
 </html>