From 1397e45cca439c6cfe084952ae12adaf25b3b0a6 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Sun, 5 Apr 2009 23:38:37 +0000 Subject: [PATCH] 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'). git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@285 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/fuzzy_match.py | 9 ++++++++- conifer/syrup/models.py | 4 ++++ conifer/syrup/views.py | 7 ++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/conifer/syrup/fuzzy_match.py b/conifer/syrup/fuzzy_match.py index a40ab87..4e53917 100644 --- a/conifer/syrup/fuzzy_match.py +++ b/conifer/syrup/fuzzy_match.py @@ -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 @@ def rank_pending_items(dct): 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)) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 96ef4ae..6ae9ac6 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -628,3 +628,7 @@ class PhysicalObject(m.Model): """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) diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 39f7237..892cc70 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -1353,7 +1353,6 @@ def phys_mark_arrived(request): @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 @@ def phys_mark_arrived_match(request): 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') -- 2.11.0