[open-ils-commits] r285 - servres/trunk/conifer/syrup (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Apr 5 19:38:38 EDT 2009


Author: gfawcett
Date: 2009-04-05 19:38:37 -0400 (Sun, 05 Apr 2009)
New Revision: 285

Modified:
   servres/trunk/conifer/syrup/fuzzy_match.py
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views.py
Log:
tightened fuzzy-match results: only show items that are not already arrived.

Note, having a barcode in metadata isn't enough to mean 'arrived', you
also need a live PhysicalObject (where 'live' means 'no departed
timestamp').


Modified: servres/trunk/conifer/syrup/fuzzy_match.py
===================================================================
--- servres/trunk/conifer/syrup/fuzzy_match.py	2009-04-05 23:38:32 UTC (rev 284)
+++ servres/trunk/conifer/syrup/fuzzy_match.py	2009-04-05 23:38:37 UTC (rev 285)
@@ -1,4 +1,5 @@
 from conifer.syrup import models
+from django.db.models import Q
 
 #http://www.poromenos.org/node/87. Credit to Poromenos. It's under BSD.
 def levenshtein_distance(first, second):
@@ -27,7 +28,13 @@
     publisher = dct.get('dc:publisher','')
     pubdate  = dct.get('dc:pubdate','')
 
-    all_pending_items = models.Item.objects.filter(item_type='PHYS') # not right... also, prefetch metadata
+    # not right... also, prefetch metadata
+    all_items = models.Item.objects.select_related('metadata')
+    all_pending_items = all_items.filter(Q(item_type='PHYS'), 
+                                         ~Q(metadata__name='syrup:barcode'))
+    all_pending_items = all_items.filter(Q(item_type='PHYS'), 
+                                         ~Q(metadata__name='syrup:barcode',
+                                            metadata__value__in=[p.barcode for p in models.PhysicalObject.live_objects()]))
     results = []
     # not sure I like these weights, but let's play a bit.
     METRICS = (('dc:title', 1), ('dc:creator', 1), ('dc:publisher', 0.5), ('dc:pubdate', 0.25))

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-04-05 23:38:32 UTC (rev 284)
+++ servres/trunk/conifer/syrup/models.py	2009-04-05 23:38:37 UTC (rev 285)
@@ -628,3 +628,7 @@
         """Find object by barcode, searching *only* the non-departed items."""
         res = cls.objects.filter(departed=None, barcode=barcode)
         return res and res[0] or None
+
+    @classmethod
+    def live_objects(cls):
+        return cls.objects.filter(departed=None)

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-04-05 23:38:32 UTC (rev 284)
+++ servres/trunk/conifer/syrup/views.py	2009-04-05 23:38:37 UTC (rev 285)
@@ -1353,7 +1353,6 @@
 
 @admin_only        
 def phys_mark_arrived_match(request):
-    #[(u'barcode', u'30007000110717'), (u'choose_27', u'on')]
     choices = [int(k.split('_')[1]) for k in request.POST if k.startswith('choose_')]
     if not choices:
         return simple_message(_('No matching items selected!'),
@@ -1372,8 +1371,10 @@
 
         for c in choices:
             item = models.Item.objects.get(pk=c)
-            if not item.barcode():
-                item.metadata_set.create(name='syrup:barcode', value=barcode)
+            current_bc = item.barcode()
+            if current_bc:
+                item.metadata_set.filter(name='syrup:barcode').delete()
+            item.metadata_set.create(name='syrup:barcode', value=barcode)
             item.save()
     return g.render('phys/mark_arrived_outcome.xhtml')
 



More information about the open-ils-commits mailing list