[open-ils-commits] r193 - in servres/trunk/conifer: syrup templates templates/admin (artunit)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Mar 17 09:16:46 EDT 2009


Author: artunit
Date: 2009-03-17 09:16:45 -0400 (Tue, 17 Mar 2009)
New Revision: 193

Modified:
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/admin/index.xhtml
   servres/trunk/conifer/templates/paginate.xhtml
   servres/trunk/conifer/templates/zsearch_results.xhtml
Log:
browsing z39.50 using paginator

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-03-17 03:33:03 UTC (rev 192)
+++ servres/trunk/conifer/syrup/views.py	2009-03-17 13:16:45 UTC (rev 193)
@@ -811,24 +811,47 @@
 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 @@
                 # 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 @@
                     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())
 
 

Modified: servres/trunk/conifer/templates/admin/index.xhtml
===================================================================
--- servres/trunk/conifer/templates/admin/index.xhtml	2009-03-17 03:33:03 UTC (rev 192)
+++ servres/trunk/conifer/templates/admin/index.xhtml	2009-03-17 13:16:45 UTC (rev 193)
@@ -17,7 +17,8 @@
     <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>

Modified: servres/trunk/conifer/templates/paginate.xhtml
===================================================================
--- servres/trunk/conifer/templates/paginate.xhtml	2009-03-17 03:33:03 UTC (rev 192)
+++ servres/trunk/conifer/templates/paginate.xhtml	2009-03-17 13:16:45 UTC (rev 193)
@@ -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">
@@ -18,16 +18,16 @@
   </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>

Modified: servres/trunk/conifer/templates/zsearch_results.xhtml
===================================================================
--- servres/trunk/conifer/templates/zsearch_results.xhtml	2009-03-17 03:33:03 UTC (rev 192)
+++ servres/trunk/conifer/templates/zsearch_results.xhtml	2009-03-17 13:16:45 UTC (rev 193)
@@ -15,14 +15,22 @@
   </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>



More information about the open-ils-commits mailing list