[open-ils-commits] r244 - in servres/trunk/conifer: . syrup templates (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Apr 2 21:30:53 EDT 2009


Author: gfawcett
Date: 2009-04-02 21:30:52 -0400 (Thu, 02 Apr 2009)
New Revision: 244

Added:
   servres/trunk/conifer/TODO
Modified:
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/search_results.xhtml
Log:
search-box now handles barcode and short-number searches.

Well, sort of. I'm using Item ID for 'short-number' right now, and
that's not quite correct. Barcode searches are correct, though.

Added: servres/trunk/conifer/TODO
===================================================================
--- servres/trunk/conifer/TODO	                        (rev 0)
+++ servres/trunk/conifer/TODO	2009-04-03 01:30:52 UTC (rev 244)
@@ -0,0 +1,7 @@
+* a short-number for physical items. Sort of a barcode, but intended
+  for easier communicatinon between patrons and staff.
+
+  * Update views.search() when this is in place.
+
+* ...
+

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-04-02 04:15:47 UTC (rev 243)
+++ servres/trunk/conifer/syrup/models.py	2009-04-03 01:30:52 UTC (rev 244)
@@ -401,6 +401,10 @@
         creators = self.metadata_set.filter(name='dc:creator')
         return creators and creators[0].value or None
 
+    def barcode(self):
+        bc = self.metadata_set.filter(name='syrup:barcode')
+        return bc and bc[0].value or None
+
     def author_hl(self, terms):
         hl_author = self.author()
 

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-04-02 04:15:47 UTC (rev 243)
+++ servres/trunk/conifer/syrup/views.py	2009-04-03 01:30:52 UTC (rev 244)
@@ -843,7 +843,6 @@
         - page through item entries
         If in_course is provided, then limit search to the contents of the specified course.
     '''
-    query_string = ''
     found_entries = None
     page_num = int(request.GET.get('page', 1))
     count = int(request.GET.get('count', 5))
@@ -859,22 +858,36 @@
 
     if len(query_string) > 0:
         norm_query = normalize_query(query_string)
+        # we start with an empty results_list, as a default
+        results_list = models.Item.objects.filter(pk=-1)
 
-        #item search - this will be expanded
+        # numeric search: If the query-string is a single number, then
+        # we do an item-ID search, or a barcode search.  fixme:
+        # item-ID is not a good short-id, since the physical item may
+        # be represented in multiple Item records. We need a
+        # short-number for barcodes.
 
-        # fixme, when moving author to the Metadata table, we can no
-        # longer do a straight search on author. Using
-        # 'metadata__value' sort of works, but also searches other
-        # metadata fields. 
+        if re.match(r'\d+', query_string):
+            # Search by short ID.
+            results_list = models.Item.objects.filter(pk=query_string,
+                                                      item_type='PHYS')
+            if not results_list:
+                # Search by barcode.
+                results_list = models.Item.objects.filter(
+                    item_type='PHYS',
+                    metadata__name='syrup:barcode', 
+                    metadata__value=query_string)
+        else:
+            # Textual (non-numeric) queries.
+            item_query = get_query(query_string, ['title', 'metadata__value'])
+                #need to think about sort order here, probably better by author (will make sortable at display level)
+            results_list = models.Item.objects.filter(item_query)
 
-        item_query = get_query(query_string, ['title', 'metadata__value'])
-        #need to think about sort order here, probably better by author (will make sortable at display level)
-        results_list = models.Item.objects.filter(item_query).order_by('title')
         if in_course:
             results_list = results_list.filter(course=in_course)
+        results_list = results_list.order_by('title')
         results_len = len(results_list)
-        paginator = Paginator( results_list,
-            count)
+        paginator = Paginator(results_list, count)
 
         #course search
         if in_course:

Modified: servres/trunk/conifer/templates/search_results.xhtml
===================================================================
--- servres/trunk/conifer/templates/search_results.xhtml	2009-04-02 04:15:47 UTC (rev 243)
+++ servres/trunk/conifer/templates/search_results.xhtml	2009-04-03 01:30:52 UTC (rev 244)
@@ -74,6 +74,7 @@
         <td>${Markup(item.author_hl(norm_query))}</td>
         <td><a href="${item.item_url('meta')}">${Markup(item.title_hl(norm_query))}</a></td>
 	<td><a href="${item.course.course_url()}">${item.course.title}</a></td>
+	<td><span py:if="item.item_type=='PHYS'">${item.id} &bull; ${item.barcode()}</span></td>
     </span>
     ${pagetable(paginator, count, pagerow, pageheader)}
 



More information about the open-ils-commits mailing list