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):
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))
"""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)
@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!'),
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')