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

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Apr 5 18:28:03 EDT 2009


Author: gfawcett
Date: 2009-04-05 18:27:58 -0400 (Sun, 05 Apr 2009)
New Revision: 282

Modified:
   servres/trunk/conifer/TODO
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views.py
Log:
better unique-physical-object detection; friendlier error message on collision.

Modified: servres/trunk/conifer/TODO
===================================================================
--- servres/trunk/conifer/TODO	2009-04-05 21:32:10 UTC (rev 281)
+++ servres/trunk/conifer/TODO	2009-04-05 22:27:58 UTC (rev 282)
@@ -3,16 +3,12 @@
 IMPORTANT:
 
 * finish the physical-item received workflow.
-  * how to model 'received' in the database?
+  * nicer error-message if smallint already taken.
 
 * if someone has item checked out, show due date/time on item-about page.
 
 * does 'move to new heading' show up in the right places? Should be like 'edit'.
 
-* 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)
-
 * Import of reserves data from Leddy voyager. Laurentian, others?
 
 * People should be able to register themselves into open courses.

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-04-05 21:32:10 UTC (rev 281)
+++ servres/trunk/conifer/syrup/models.py	2009-04-05 22:27:58 UTC (rev 282)
@@ -596,19 +596,20 @@
     # an optional small-integer used as a human-shareable barcode by some institutions.
     smallint    = m.IntegerField(blank=True, null=True)
 
+    def __unicode__(self):
+        return '%s (%s) %s' % (self.barcode, self.smallint, self.departed and 'gone' or 'live')
 
     def save(self, force_insert=False, force_update=False):
         # Must ensure that barcode is unique for non-departed items. Same with smallint
-        try:
-            unique_thing = 'barcode'
-            already = PhysicalObject.objects.exclude(pk=self.id).get(departed=None)
-            unique_thing = 'smallint'
-            if self.smallint:
-                already = PhysicalObject.objects.exclude(pk=self.id).get(smallint=self.smallint)
-        except PhysicalObject.DoesNotExist:
-            super(PhysicalObject, self).save(force_insert, force_update)
-        else:
-            raise AssertionError, '%s is not unique in active PhysicalObject collection.' % unique_thing
+        live_objs = PhysicalObject.objects.exclude(pk=self.id).filter(departed=None)
+        same_barcode = live_objs.filter(barcode=self.barcode)
+        assert not same_barcode, \
+            'Barcode is not unique in active PhysicalObject collection.'
+        if self.smallint:
+            same_smallint = live_objs.filter(smallint=self.smallint)
+            assert not same_smallint, \
+                'Small Number is not unique in active PhysicalObject collection.'
+        super(PhysicalObject, self).save(force_insert, force_update)
 
     @classmethod
     def by_smallint(cls, smallint):

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-04-05 21:32:10 UTC (rev 281)
+++ servres/trunk/conifer/syrup/views.py	2009-04-05 22:27:58 UTC (rev 282)
@@ -1359,16 +1359,19 @@
         barcode = request.POST.get('barcode', '').strip()
         assert barcode
         smallint = request.POST.get('smallint', '').strip() or None
-        phys = models.PhysicalObject(barcode=barcode,
-                                     receiver = request.user,
-                                     smallint = smallint)
-        phys.save()
+        try:
+            phys = models.PhysicalObject(barcode=barcode,
+                                         receiver = request.user,
+                                         smallint = smallint)
+            phys.save()
+        except Exception, e:
+            return simple_message(_('Error'), repr(e), go_back=True)
 
         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()
-    return simple_message(_('Matches saved.'), '', go_back=False)
+    return g.render('phys/mark_arrived_outcome.xhtml')
 
 



More information about the open-ils-commits mailing list