[open-ils-commits] r455 - in servres/trunk/conifer: . custom libsystems/z3950 syrup/views templates/components templates/item (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue May 5 22:12:40 EDT 2009


Author: gfawcett
Date: 2009-05-05 22:12:39 -0400 (Tue, 05 May 2009)
New Revision: 455

Modified:
   servres/trunk/conifer/TODO
   servres/trunk/conifer/custom/lib_integration.py
   servres/trunk/conifer/libsystems/z3950/yaz_search.py
   servres/trunk/conifer/syrup/views/items.py
   servres/trunk/conifer/templates/components/course.xhtml
   servres/trunk/conifer/templates/item/item_add_cat_search.xhtml
Log:
Z39.50 madness! Now will paginate through all hits. Items with 856$9 added as URLs, not Physical Items.


Modified: servres/trunk/conifer/TODO
===================================================================
--- servres/trunk/conifer/TODO	2009-05-06 00:01:08 UTC (rev 454)
+++ servres/trunk/conifer/TODO	2009-05-06 02:12:39 UTC (rev 455)
@@ -8,10 +8,6 @@
 
 * set up a proper issue-tracker?
 
-* Z39.50 may return e-journal records (with 856u hyperlinks) and other
-  non-physical items. 859$9 is a definitive indicator in the Conifer
-  (Evergreen?) context.
-
 * opensrf alternatives for SIP calls?
 
 * need more than 10 results on physical-item search results.
@@ -70,3 +66,7 @@
 > Sequencing -- easy! Save -- maybe make a  button?  [where's my narrative?]
   [I didn't make it a button, but I did add the narrative back.]
 
+* Z39.50 may return e-journal records (with 856u hyperlinks) and other
+  non-physical items. 856$9 is a definitive indicator in the Conifer
+  (Evergreen?) context.
+

Modified: servres/trunk/conifer/custom/lib_integration.py
===================================================================
--- servres/trunk/conifer/custom/lib_integration.py	2009-05-06 00:01:08 UTC (rev 454)
+++ servres/trunk/conifer/custom/lib_integration.py	2009-05-06 02:12:39 UTC (rev 455)
@@ -85,7 +85,8 @@
     # title-detail URL, then return just that one item.
     if query.startswith(EG_BASE):
         results = marcxml_to_dictionary(I.url_to_marcxml(query), multiples=True)
+        numhits = len(results)
     else:
         cat_host, cat_db = settings.Z3950_CONFIG
-        results = yaz_search.search(cat_host, cat_db, query, start, limit)
-    return results
+        results, numhits = yaz_search.search(cat_host, cat_db, query, start, limit)
+    return results, numhits

Modified: servres/trunk/conifer/libsystems/z3950/yaz_search.py
===================================================================
--- servres/trunk/conifer/libsystems/z3950/yaz_search.py	2009-05-06 00:01:08 UTC (rev 454)
+++ servres/trunk/conifer/libsystems/z3950/yaz_search.py	2009-05-06 02:12:39 UTC (rev 455)
@@ -43,7 +43,7 @@
     numhits = int(server.match.group(1)) 
     if start > numhits:
         warnings.warn('asked z3950 to start at %d, but only %d results.' % (start, numhits))
-        return []
+        return [], 0
 
     # how many to present? At most 10 for now.
     to_show = min(numhits-1, limit)
@@ -56,7 +56,7 @@
     if err:
         warnings.warn('error during z3950 conversation.')
         server.close()
-        return []
+        return [], 0
 
     raw_records = []
     err = None
@@ -73,12 +73,11 @@
     for rec in raw_records:
         try:
             rec = _marc_utf8_pattern.sub(_decode_marc_utf8, rec)
-            print type(rec)
             dct = marcxml_to_dictionary(rec)
         except 'x':
             raise rec
         parsed.append(dct)
-    return parsed
+    return parsed, numhits
 
 
 # decoding MARC \X.. UTF-8 patterns.

Modified: servres/trunk/conifer/syrup/views/items.py
===================================================================
--- servres/trunk/conifer/syrup/views/items.py	2009-05-06 00:01:08 UTC (rev 454)
+++ servres/trunk/conifer/syrup/views/items.py	2009-05-06 02:12:39 UTC (rev 455)
@@ -165,22 +165,19 @@
     #----------
 
     if request.method != 'POST':
-        return g.render('item/item_add_cat_search.xhtml', results=[], query='', 
-                        course=course, parent_item=parent_item)
-
-    # POST handler
-    query     = request.POST.get('query','').strip()
-    raw_pickitem = request.POST.get('pickitem', '').strip()
-    if not raw_pickitem:
-        # process the query.
-        assert query, 'must provide a query.'
-        start, limit = (1, 20)
-        results = lib_integration.cat_search(query, start, limit)
+        if not 'query' in request.GET:
+            return g.render('item/item_add_cat_search.xhtml', results=[], query='', 
+                            course=course, parent_item=parent_item)
+        query = request.GET.get('query','').strip()
+        start, limit = (int(request.GET.get(k,v)) for k,v in (('start',1),('limit',10)))
+        results, numhits = lib_integration.cat_search(query, start, limit)
         return g.render('item/item_add_cat_search.xhtml', 
                         results=results, query=query, 
+                        start=start, limit=limit, numhits=numhits,
                         course=course, parent_item=parent_item)
     else:
         # User has selected an item; add it to course site.
+        raw_pickitem = request.POST.get('pickitem', '').strip()
         #fixme, this block copied from item_add. refactor.
         parent_item_id = item_id
         if parent_item_id == '0': 
@@ -197,10 +194,18 @@
         pickitem = simplejson.loads(raw_pickitem)
         dublin = marcxml_dictionary_to_dc(pickitem)
 
+        # one last thing. If this picked item has an 856$9 field, then
+        # it's an electronic resource, not a physical item. In that
+        # case, we add it as a URL, not a PHYS.
+        if '8569' in pickitem:
+            dct = dict(item_type='URL', url=pickitem.get('856u'))
+        else:
+            dct = dict(item_type='PHYS')
+
         item = course.item_set.create(parent_heading=parent_item,
                                       sort_order=next_order,
                                       title=dublin.get('dc:title','Untitled'),
-                                      item_type='PHYS')
+                                      **dct)
         item.save()
 
         for dc, value in dublin.items():
@@ -208,7 +213,7 @@
         # store the whole darn MARC-dict as well (JSON)
         item.metadata_set.create(item=item, name='syrup:marc', value=raw_pickitem)
         item.save()
-        return HttpResponseRedirect('../../../%d/' % item.id)
+        return HttpResponseRedirect('../../../%d/meta' % item.id)
 
 #------------------------------------------------------------
 

Modified: servres/trunk/conifer/templates/components/course.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/course.xhtml	2009-05-06 00:01:08 UTC (rev 454)
+++ servres/trunk/conifer/templates/components/course.xhtml	2009-05-06 02:12:39 UTC (rev 455)
@@ -73,7 +73,7 @@
       <li><a href="${prefix}add/?item_type=HEADING">Subheading</a></li>
       <li><a href="${prefix}add/?item_type=URL">URL</a></li>
       <li><a href="${prefix}add/?item_type=ELEC">Electronic Document</a></li>
-      <li><a href="${prefix}add/?item_type=PHYS">Physical Book/Document</a></li>
+      <li><a href="${prefix}add/?item_type=PHYS">Physical Item or Catalogued Electronic Item</a></li>
     </ul>
   </div>
 

Modified: servres/trunk/conifer/templates/item/item_add_cat_search.xhtml
===================================================================
--- servres/trunk/conifer/templates/item/item_add_cat_search.xhtml	2009-05-06 00:01:08 UTC (rev 454)
+++ servres/trunk/conifer/templates/item/item_add_cat_search.xhtml	2009-05-06 02:12:39 UTC (rev 455)
@@ -1,7 +1,7 @@
 <?python
 from django.utils.simplejson import dumps
 from conifer.libsystems.z3950.marcxml import marcxml_dictionary_to_dc as to_dublin
-title = _('Add physical item: Catalogue search')
+title = _('Add physical or electronic item, by catalogue search')
 dc_keys = ['dc:title', 'dc:creator', 'dc:publisher', 'dc:date']
 ?>
 <html xmlns="http://www.w3.org/1999/xhtml"
@@ -16,7 +16,7 @@
     <!-- !This ought to be in paginate.xhtml, not here. how to do? -->
     $(function() { $('.pagetable').tablesorter(); });
   </script>
-  <script py:if="request.method != 'POST'">		       <!-- !focus on query box if nothing to scroll. -->
+  <script py:if="not 'query' in request.GET">		       <!-- !focus on query box if nothing to scroll. -->
     $(function() { $('#query').focus(); });
   </script>
 </head>
@@ -24,24 +24,40 @@
     ${course_banner(course)}
     ${nested_title(parent_item)}
     <h2>${title}</h2>
-    <form method="POST" action=".">
+    <form method="GET" action=".">
       <input type="text" id="query" name="query" value="${query}" 
 	     style="font-size: larger; width: 600px;"/>
       <input type="submit" value="Search"/>
 	${go_back_link()}
 
     </form>
-
-    <table class="pagetable" py:if="request.method == 'POST'">
+    <div py:def="page_control" py:if="results">
+      <p>
+	${start}&ndash;${min(numhits, start+limit-1)} of ${numhits} results.
+	<span py:if="start-limit&gt;0">
+	  <a href=".?query=${query}&amp;start=${start-limit}&amp;limit=${limit}">Previous ${limit}</a>
+	  &bull;
+	</span>
+	<span py:if="start+limit&lt;numhits">
+	  <a href=".?query=${query}&amp;start=${start+limit}&amp;limit=${limit}">Next ${limit}</a>
+	</span>
+      </p>
+    </div>
+    ${page_control()}
+    <table class="pagetable" py:if="'query' in request.GET">
       <thead>
-	<tr><th>Title</th><th>Author</th><th>Publisher</th><th>PubDate</th></tr>
+	<tr><th>#</th><th>Title</th><th>Author</th><th>Publisher</th><th>PubDate</th></tr>
       </thead>
       <tbody py:for="resultnum, res in enumerate(results)"
 	     py:with="dc=to_dublin(res)">
 	<tr>
+	  <td>${resultnum+start}.</td>
 	  <td>
 	    ${dc.get('dc:title', '???')}
 	    <a href="javascript:$('#full_${resultnum}').toggle(); void(0);">details</a>
+	    <p py:if="res.get('8569')" style="margin: 8px 0; font-size: 90%; color: darkred;">
+	      Electronic resource. <a href="${res.get('856u')}">view</a>
+	    </p>
 	  </td>
 	  <td py:for="k in dc_keys[1:]">${dc.get(k) or '&mdash;'}</td>
 	  <td>
@@ -63,5 +79,6 @@
 	</tr>
       </tbody>
     </table>
+    ${page_control()}
  </body>
 </html>



More information about the open-ils-commits mailing list