Add small-int at item-arrival; search on small-ints.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Sun, 5 Apr 2009 21:17:25 +0000 (21:17 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Sun, 5 Apr 2009 21:17:25 +0000 (21:17 +0000)
I don't yet have a post-arrival method of setting a small integer
ID. Not sure what the requirements are, so I'm punting for the moment.

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

conifer/syrup/models.py
conifer/syrup/views.py
conifer/templates/item_metadata.xhtml
conifer/templates/search_results.xhtml

index b33818f..4258dd6 100644 (file)
@@ -410,6 +410,20 @@ class Item(m.Model):
         bc = self.metadata_set.filter(name='syrup:barcode')
         return bc and bc[0].value or None
 
+    def smallint(self):
+        bc = self.barcode()
+        phys = PhysicalObject.by_barcode(bc)
+        return phys and phys.smallint or None
+
+    @classmethod
+    def with_smallint(cls, smallint):
+        phys = PhysicalObject.by_smallint(smallint)
+        barcode = phys and phys.barcode or None
+        if not barcode:
+            return cls.objects.filter(pk=-1) # empty set
+        else:
+            return cls.with_barcode(barcode)
+        
     @classmethod
     def with_barcode(cls, barcode):
         return cls.objects.filter(metadata__name='syrup:barcode', 
@@ -594,6 +608,13 @@ class PhysicalObject(m.Model):
             raise AssertionError, 'barcode is not unique in active PhysicalObject collection.'
 
     @classmethod
+    def by_smallint(cls, smallint):
+        """Find object by smallint, searching *only* the non-departed items."""
+        assert smallint
+        res = cls.objects.filter(departed=None, smallint=smallint)
+        return res and res[0] or None
+
+    @classmethod
     def by_barcode(cls, barcode):
         """Find object by barcode, searching *only* the non-departed items."""
         res = cls.objects.filter(departed=None, barcode=barcode)
index 1c181c2..a5d80b1 100644 (file)
@@ -903,8 +903,7 @@ def search(request, in_course=None):
 
         if re.match(r'\d+', query_string):
             # Search by short ID.
-            results_list = models.Item.objects.filter(pk=query_string,
-                                                      item_type='PHYS')
+            results_list = models.Item.with_smallint(query_string)
             if not results_list:
                 # Search by barcode.
                 results_list = models.Item.objects.filter(
@@ -1359,17 +1358,17 @@ def phys_mark_arrived_match(request):
     else:
         barcode = request.POST.get('barcode', '').strip()
         assert barcode
-        smallint = request.POST.get('smallint', '').strip() # will be '' for now.
+        smallint = request.POST.get('smallint', '').strip() or None
         phys = models.PhysicalObject(barcode=barcode,
                                      receiver = request.user,
-                                     smallint = smallint or None)
+                                     smallint = smallint)
         phys.save()
 
         for c in choices:
             item = models.Item.objects.get(pk=c)
             if not item.barcode():
                 item.metadata_set.create(name='syrup:barcode', value=barcode)
-                item.save()
+            item.save()
     return simple_message(_('Matches saved.'), '', go_back=False)
 
 
index 7121660..1bbe271 100644 (file)
@@ -3,6 +3,7 @@ from django.utils.simplejson import loads
 course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
 hier = item.hierarchy()[:-1]
 title = item.title
+smallint = item.smallint()
 metadata = item.metadata_set.all()
 is_editor = course.can_edit(request.user)
 ?>
@@ -36,6 +37,9 @@ is_editor = course.can_edit(request.user)
          py:with="avail, status = item.describe_physical_item_status()">
        <th>Status</th><td><div class="${avail and 'available' or 'unavailable'}">${status}</div></td>
       </tr>
+      <tr py:if="smallint">
+       <th>Small Number</th><td>${smallint}</td>
+      </tr>
       <tr py:if="item.url"><th>URL</th><td><a href="${item.url}">${item.url}</a></td></tr>
     </table>
     <div py:if="item.item_type=='ELEC'">
index 32aa2d8..bb7f3e4 100644 (file)
@@ -74,7 +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>
+       <td><span py:if="item.item_type=='PHYS'">${item.smallint()} &bull; ${item.barcode()}</span></td>
     </span>
     ${pagetable(paginator, count, pagerow, pageheader)}