[open-ils-commits] r275 - in servres/trunk/conifer: . libsystems/z3950 static syrup templates templates/components (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Apr 5 14:33:58 EDT 2009


Author: gfawcett
Date: 2009-04-05 14:33:55 -0400 (Sun, 05 Apr 2009)
New Revision: 275

Removed:
   servres/trunk/conifer/templates/graham_z3950_test.xhtml
Modified:
   servres/trunk/conifer/TODO
   servres/trunk/conifer/libsystems/z3950/marcxml.py
   servres/trunk/conifer/libsystems/z3950/yaz_search.py
   servres/trunk/conifer/static/main.css
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/components/course.xhtml
   servres/trunk/conifer/templates/item_add_cat_search.xhtml
   servres/trunk/conifer/templates/item_add_elec.xhtml
   servres/trunk/conifer/templates/item_add_heading.xhtml
   servres/trunk/conifer/templates/item_add_phys.xhtml
   servres/trunk/conifer/templates/item_add_url.xhtml
   servres/trunk/conifer/templates/item_metadata.xhtml
Log:
various & sundry z3950 and MARC-related improvements

Search queries no longer need explicit @and prefixes (they are now implicit);

a cleaner phys-item search-results page. Still only max 10 results showing, though.

various visual improvements.

Modified: servres/trunk/conifer/TODO
===================================================================
--- servres/trunk/conifer/TODO	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/TODO	2009-04-05 18:33:55 UTC (rev 275)
@@ -13,6 +13,8 @@
 * People should be able to register themselves into open courses.
   That is, actually become a member of them.
 
+* accented characters in z3950 queries seem to fail. More tests needed.
+
 MAYBE:
 
 * Generating barcodes in emails, printable screens? (3 of 9 enough?)

Modified: servres/trunk/conifer/libsystems/z3950/marcxml.py
===================================================================
--- servres/trunk/conifer/libsystems/z3950/marcxml.py	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/libsystems/z3950/marcxml.py	2009-04-05 18:33:55 UTC (rev 275)
@@ -38,8 +38,16 @@
         value = dct.get(marc)
         if value:
             out[dc] = value
-    if '245b' in meta and 'dc:title' in out:
-        out['dc:title'] += (' %s' % meta['245b'])
+    title = out.get('dc:title')
+    if title:
+        if '245b' in dct:
+            title += (' %s' % dct['245b'])
+        # if title ends with a single character, strip it. usually a
+        # spurious punctuation character.
+        init, last = title.rsplit(' ',1)
+        if len(last) == 1:
+            title = init
+        out['dc:title'] = title
     return out
 
     

Modified: servres/trunk/conifer/libsystems/z3950/yaz_search.py
===================================================================
--- servres/trunk/conifer/libsystems/z3950/yaz_search.py	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/libsystems/z3950/yaz_search.py	2009-04-05 18:33:55 UTC (rev 275)
@@ -12,14 +12,26 @@
 
 LOG = sys.stderr #None              #  for pexpect debugging, try LOG = sys.stderr
 YAZ_CLIENT = 'yaz-client'
-GENERAL_TIMEOUT = 20
-PRESENT_TIMEOUT = 30
+GENERAL_TIMEOUT = 40
+PRESENT_TIMEOUT = 60
 
 def search(host, database, query, start=1, limit=None):
 
+    # first, let's look at our query. I'm assuming @prefix queries for
+    # now, so we need to put queries in that form if they aren't
+    # yet. I'm also assuming query is a conjunction (terms are
+    # AND'ed) if a '@' query isn't provided.
+    if not query.startswith('@'):
+        words = [w for w in query.split(' ') if w.strip()]
+        tmp   = (['@and'] * (len(words) - 1)) + words
+        query = ' '.join(tmp)
+    query = query.encode('utf-8') # is this okay? Is it enough??
+
     server = pexpect.spawn('yaz-client', timeout=GENERAL_TIMEOUT, logfile=LOG)
     #server.expect('Z>')
-    for line in ('open %s' % host, 'base %s' % database, 'format xml'):
+    for line in ('open %s' % host, 
+                 'base %s' % database, 
+                 'format xml'):
         server.sendline(line)
         server.expect('Z>')
 

Modified: servres/trunk/conifer/static/main.css
===================================================================
--- servres/trunk/conifer/static/main.css	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/static/main.css	2009-04-05 18:33:55 UTC (rev 275)
@@ -245,6 +245,7 @@
 .metadata_table tbody td {
     padding: 8; border: #ddd 1px solid;
 }
+.metadata_table input { width: 600; }
 
 .metadata_table tbody th {
     background-color: #eee;
@@ -271,4 +272,4 @@
 
 ul.heading_tree li  { list-style: none; }
 ul.heading_tree { margin: 0; padding-left: 0; }
-ul.heading_tree ul { margin: 0; padding-left: 25; }
\ No newline at end of file
+ul.heading_tree ul { margin: 0; padding-left: 25; }

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/syrup/views.py	2009-04-05 18:33:55 UTC (rev 275)
@@ -275,23 +275,6 @@
     res_str = "" . join(collector)
     return g.render('z3950_test.xhtml', res_str=res_str)
 
-def graham_z3950_test(request):
-    raise NotImplementedError   # delete this function, its template, etc.
-    query = request.GET.get('query', '@and "Denis" "Gravel"')
-    from conifer.libsystems.z3950 import yaz_search
-    from conifer.libsystems.evergreen.item_status import lookup_availability
-    host, db, query = ('dwarf.cs.uoguelph.ca:2210', 'conifer', query)
-    #host, db, query = ('z3950.loc.gov:7090', 'VOYAGER', '@attr 1=4 @attr 4=1 "dylan"')
-    results = yaz_search.search(host, db, query)
-    for result in results:
-        bibid = result.get('901c')
-        if bibid:
-            # it would be better to do these asynchronously.
-            avail = lookup_availability(bibid) 
-            if avail:
-                result['avail'] = avail
-    return g.render('graham_z3950_test.xhtml', results=results, query=query)
-
 def browse(request, browse_option=''):
     #the defaults should be moved into a config file or something...
     page_num = int(request.GET.get('page', 1))
@@ -728,7 +711,7 @@
 @instructors_only
 def item_add_cat_search(request, course_id, item_id):
     if request.method != 'POST':
-        return g.render('item_add_cat_search.xhtml', results=[], query='@and dylan thomas')
+        return g.render('item_add_cat_search.xhtml', results=[], query='')
 
     # POST handler
     query     = request.POST.get('query','').strip()
@@ -743,7 +726,8 @@
         # User has selected an item; add it to course site.
         #fixme, this block copied from item_add. refactor.
         parent_item_id = item_id
-        if parent_item_id=='0':
+        if parent_item_id == '0': 
+            # no heading (toplevel)
             parent_item = None
             course = get_object_or_404(models.Course, pk=course_id)
         else:
@@ -757,14 +741,13 @@
         dublin = marcxml_dictionary_to_dc(pickitem)
 
         item = course.item_set.create(parent_heading=parent_item,
-                                      title=pickitem.get('245a', 'Untitled'),
+                                      title=dublin.get('dc:title','Untitled'),
                                       item_type='PHYS')
         item.save()
 
         for dc, value in dublin.items():
             md = item.metadata_set.create(item=item, name=dc, value=value)
-        # store the whole darn MARC-dict as well.
-        json = simplejson.dumps(pickitem)
+        # 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)

Modified: servres/trunk/conifer/templates/components/course.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/course.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/components/course.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -93,7 +93,7 @@
       <p py:if="show_more"><a href="javascript:show_metadata();" id="show_metadata">Show more attributes</a></p>
       <div  id="metadatatable">
       ${Markup(metadata_formset.management_form)}
-      <table class="pagetable">
+      <table class="metadata_table">
 	<thead>
 	  <tr><th>Attribute</th><th>Value</th><th/><th>Delete?</th></tr>
 	</thead>

Deleted: servres/trunk/conifer/templates/graham_z3950_test.xhtml
===================================================================
--- servres/trunk/conifer/templates/graham_z3950_test.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/graham_z3950_test.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -1,52 +0,0 @@
-<?python
-title = _('Z39.50 Test, with Evergreen giving item availability')
-# I just made up these keys...
-keys = [('245a', 'Title'), ('100a', 'Author'), ('260c', 'PubDate'), ('901c', 'BibID')]
-?>
-<html xmlns="http://www.w3.org/1999/xhtml"
-      xmlns:xi="http://www.w3.org/2001/XInclude"
-      xmlns:py="http://genshi.edgewall.org/">
-<xi:include href="master.xhtml"/>
-<xi:include href="paginate.xhtml"/>
-<head>
-  <title>${title}</title>
-  <style>
-    tbody.available { background-color: #dfd; }
-    .lesser { font-size: smaller; color: gray; display: none; }
-  </style>
-  <script type="text/javascript">
-    <!-- !This ought to be in paginate.xhtml, not here. how to do? -->
-    $(function() { $('.pagetable').tablesorter(); });
-  </script>
-</head>
-<body>
-    <h1>${title}</h1>
-    <form method="GET" action=".">
-      <input type="text" name="query" value="${query}" style="font-size: larger;"/>
-      <input type="submit" value="Search"/>
-    </form>
-    <p><a href="javascript:$('.lesser').show(); void(0);">show more detail</a></p>
-    <table py:for="res in results" style="margin: 1em 0; border: black 1px solid;">
-      <?python 
-	is_available = res.get('avail') and (res['avail']['available'] or res['avail']['holdable'])
-      ?>
-      <tbody class="${is_available and 'available' or ''}">
-      <tr py:for="k, title in keys" py:if="k in res">
-	<th>${title}</th><td>${res[k]}</td>
-      </tr>
-      <tr py:if="'avail' in res">
-	<th>Availability</th>
-	<td>
-	  <div py:for="k,v in res['avail'].items()">
-	  ${'%s = %s' % (k,v)}
-	  </div>
-	</td>
-      </tr>
-      <?python allkeys = res.keys(); allkeys.sort(); ?>
-      <tr py:for="k in allkeys" class="lesser">
-	<th>${k}</th><td>${res[k]}</td>
-      </tr>
-      </tbody>
-    </table>
-</body>
-</html>

Modified: servres/trunk/conifer/templates/item_add_cat_search.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add_cat_search.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/item_add_cat_search.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -1,8 +1,8 @@
 <?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')
-# I just made up these keys...
-keys = [('245a', 'Title'), ('100a', 'Author'), ('260b', 'Publisher'), ('260c', 'PubDate'), ('700a', 'Editor')]
+dc_keys = ['dc:title', 'dc:creator', 'dc:publisher', 'dc:date']
 ?>
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:xi="http://www.w3.org/2001/XInclude"
@@ -11,9 +11,6 @@
 <xi:include href="paginate.xhtml"/>
 <head>
   <title>${title}</title>
-  <style>
-    .lesser { font-size: smaller; color: gray; display: none; }
-  </style>
   <script type="text/javascript">
     <!-- !This ought to be in paginate.xhtml, not here. how to do? -->
     $(function() { $('.pagetable').tablesorter(); });
@@ -25,28 +22,41 @@
 <body>
     <h1>${title}</h1>
     <form method="POST" action=".">
-      <input type="text" id="query" name="query" value="${query}" style="font-size: larger;"/>
+      <input type="text" id="query" name="query" value="${query}" 
+	     style="font-size: larger; width: 600;"/>
       <input type="submit" value="Search"/>
     </form>
-    <p><a href="javascript:$('.lesser').show(); void(0);">show more detail</a></p>
-    <table py:for="res in results" style="margin: 1em 0; border: black 1px solid;">
-      <tbody>
-      <tr py:for="k, title in keys" py:if="k in res">
-	<th>${title}</th><td>${res[k]}</td>
-      </tr>
-      <tr>
-	<th/><td>
-	<form action="." method="POST">
-	  <input type="hidden" name="pickitem" value="${dumps(res)}"/>
-	  <input type="submit" value="Pick this item"/>
-	</form>
-      </td>
-      </tr>
-      <?python allkeys = res.keys(); allkeys.sort(); ?>
-      <tr py:for="k in allkeys" class="lesser">
-	<th>${k}</th><td>${res[k]}</td>
-      </tr>
+
+    <table class="pagetable">
+      <thead>
+	<tr><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>
+	    ${dc.get('dc:title', '???')}
+	    <a href="javascript:$('#full_${resultnum}').toggle(); void(0);">details</a>
+	  </td>
+	  <td py:for="k in dc_keys[1:]">${dc.get(k) or '&mdash;'}</td>
+	  <td>
+	    <form action="." method="POST">
+	      <input type="hidden" name="pickitem" value="${dumps(res)}"/>
+	      <input type="submit" value="Pick this item"/>
+	    </form>
+	  </td>
+	</tr>
+	<tr id="full_${resultnum}" style="display: none;">
+	  <td colspan="4" style="padding-left: 36;">
+	    <table class="metadata_table">
+	      <?python allkeys = res.keys(); allkeys.sort(); ?>
+	      <tr py:for="k in allkeys">
+		<th>${k}</th><td>${res[k]}</td>
+	      </tr>
+	    </table>
+	  </td>
+	</tr>
       </tbody>
     </table>
-</body>
+ </body>
 </html>

Modified: servres/trunk/conifer/templates/item_add_elec.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add_elec.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/item_add_elec.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -24,7 +24,7 @@
     <div py:if="not is_edit">
       <form action=".?item_type=${item_type}" method="POST"
 	    enctype="multipart/form-data">
-	<table>
+	<table class="metadata_table">
 	  <tr><th>Title of document</th><td><input type="text" 
 	  name="title"
 	  value="${item.title}"/></td></tr>

Modified: servres/trunk/conifer/templates/item_add_heading.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add_heading.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/item_add_heading.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -21,7 +21,7 @@
     ${offer_to_delete(item)}
     <h3>${title}</h3>
     <form action=".?item_type=${item_type}" method="POST">
-      <table>
+      <table class="metadata_table">
 	<tr><th>Heading</th><td>
 	<input type="text" name="title"
 	       value="${item.title}"/>

Modified: servres/trunk/conifer/templates/item_add_phys.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add_phys.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/item_add_phys.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -21,8 +21,13 @@
     <h3>${title}</h3>
 
     <form action=".?item_type=${item_type}" method="POST">
-      <p>Display name: <input type="text" name="title" value="${item.title}"/></p>
-
+      <table class="metadata_table">
+	<tr>
+	  <th>Display name</th>
+	  <td><input type="text" name="title" value="${item.title}"/></td>
+	</tr>
+      </table>
+      <h3>Metadata</h3>
       ${item_metadata_formset(show_more=False)}
       <p>
     	<input py:if="not is_edit" type="submit" value="Add heading"/>

Modified: servres/trunk/conifer/templates/item_add_url.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add_url.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/item_add_url.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -21,7 +21,7 @@
     ${offer_to_delete(item)}
     <h3>${title}</h3>
     <form action=".?item_type=${item_type}" method="POST">
-      <table>
+      <table class="metadata_table">
 	<tr><th>Title</th><td><input type="text" name="title" value="${item.title}"/></td></tr>
 	<tr><th>URL</th><td><input type="text" name="url" value="${item.url}"/></td></tr>
       </table>

Modified: servres/trunk/conifer/templates/item_metadata.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_metadata.xhtml	2009-04-05 15:56:01 UTC (rev 274)
+++ servres/trunk/conifer/templates/item_metadata.xhtml	2009-04-05 18:33:55 UTC (rev 275)
@@ -1,4 +1,5 @@
 <?python
+from django.utils.simplejson import loads
 course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
 hier = item.hierarchy()[:-1]
 title = item.title
@@ -41,7 +42,22 @@
       <h2 class="metadata_subhead">Additional metadata</h2>
       <table class="metadata_table">
 	<tr py:for="attr in metadata">
-	  <th>${attr.get_name_display()}</th><td>${attr.value}</td>
+	  <th>${attr.get_name_display()}</th>
+	  <td py:if="attr.name != 'syrup:marc'">
+	    ${attr.value}
+	  </td>
+	  <td py:if="attr.name == 'syrup:marc'">
+	    <div id="marcdatashow"><a href="javascript:$('#marcdata').show();$('#marcdatashow').hide();void(0);">show</a></div>
+	    <div id="marcdata" style="display: none;">
+	      <?python dct = loads(attr.value); keys=dct.keys(); keys.sort() ?>
+	      <table>
+		<tr py:for="k in keys">
+		  <th>${k}</th>
+		  <td>${dct[k]}</td>
+		</tr>
+	      </table>
+	    </div>
+	  </td>
 	</tr>
       </table>
       </div>



More information about the open-ils-commits mailing list