search-box now handles barcode and short-number searches.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 3 Apr 2009 01:30:52 +0000 (01:30 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 3 Apr 2009 01:30:52 +0000 (01:30 +0000)
Well, sort of. I'm using Item ID for 'short-number' right now, and
that's not quite correct. Barcode searches are correct, though.

git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@244 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/TODO [new file with mode: 0644]
conifer/syrup/models.py
conifer/syrup/views.py
conifer/templates/search_results.xhtml

diff --git a/conifer/TODO b/conifer/TODO
new file mode 100644 (file)
index 0000000..7ed6d55
--- /dev/null
@@ -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.
+
+* ...
+
index 7209447..f6e53d6 100644 (file)
@@ -401,6 +401,10 @@ class Item(m.Model):
         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()
 
index 08c8fa3..d293340 100644 (file)
@@ -843,7 +843,6 @@ def search(request, in_course=None):
         - 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 @@ def search(request, in_course=None):
 
     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)
+
+        # 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.
+
+        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 search - this will be expanded
-
-        # 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. 
-
-        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:
index 20dcc12..32aa2d8 100644 (file)
@@ -74,6 +74,7 @@ courses = course_list
         <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)}