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

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Apr 5 17:17:29 EDT 2009


Author: gfawcett
Date: 2009-04-05 17:17:25 -0400 (Sun, 05 Apr 2009)
New Revision: 279

Modified:
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/item_metadata.xhtml
   servres/trunk/conifer/templates/search_results.xhtml
Log:
Add small-int at item-arrival; search on small-ints.

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.

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-04-05 20:42:51 UTC (rev 278)
+++ servres/trunk/conifer/syrup/models.py	2009-04-05 21:17:25 UTC (rev 279)
@@ -410,7 +410,21 @@
         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', 
                                   metadata__value=barcode)
@@ -594,6 +608,13 @@
             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)

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-04-05 20:42:51 UTC (rev 278)
+++ servres/trunk/conifer/syrup/views.py	2009-04-05 21:17:25 UTC (rev 279)
@@ -903,8 +903,7 @@
 
         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 @@
     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)
 
 

Modified: servres/trunk/conifer/templates/item_metadata.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_metadata.xhtml	2009-04-05 20:42:51 UTC (rev 278)
+++ servres/trunk/conifer/templates/item_metadata.xhtml	2009-04-05 21:17:25 UTC (rev 279)
@@ -3,6 +3,7 @@
 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 @@
 	  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'">

Modified: servres/trunk/conifer/templates/search_results.xhtml
===================================================================
--- servres/trunk/conifer/templates/search_results.xhtml	2009-04-05 20:42:51 UTC (rev 278)
+++ servres/trunk/conifer/templates/search_results.xhtml	2009-04-05 21:17:25 UTC (rev 279)
@@ -74,7 +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>
+	<td><span py:if="item.item_type=='PHYS'">${item.smallint()} &bull; ${item.barcode()}</span></td>
     </span>
     ${pagetable(paginator, count, pagerow, pageheader)}
 



More information about the open-ils-commits mailing list