From a24e2509bf85af605b5bd32632b2cd860f798f06 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Sun, 5 Apr 2009 21:17:25 +0000 Subject: [PATCH] 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. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@279 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/models.py | 21 +++++++++++++++++++++ conifer/syrup/views.py | 9 ++++----- conifer/templates/item_metadata.xhtml | 4 ++++ conifer/templates/search_results.xhtml | 2 +- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index b33818f..4258dd6 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -410,6 +410,20 @@ class Item(m.Model): 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', @@ -594,6 +608,13 @@ class PhysicalObject(m.Model): 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) diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 1c181c2..a5d80b1 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -903,8 +903,7 @@ def search(request, in_course=None): 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 @@ def phys_mark_arrived_match(request): 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) diff --git a/conifer/templates/item_metadata.xhtml b/conifer/templates/item_metadata.xhtml index 7121660..1bbe271 100644 --- a/conifer/templates/item_metadata.xhtml +++ b/conifer/templates/item_metadata.xhtml @@ -3,6 +3,7 @@ from django.utils.simplejson import loads 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 @@ is_editor = course.can_edit(request.user) py:with="avail, status = item.describe_physical_item_status()"> Status
${status}
+ + Small Number${smallint} + URL${item.url}
diff --git a/conifer/templates/search_results.xhtml b/conifer/templates/search_results.xhtml index 32aa2d8..bb7f3e4 100644 --- a/conifer/templates/search_results.xhtml +++ b/conifer/templates/search_results.xhtml @@ -74,7 +74,7 @@ courses = course_list ${Markup(item.author_hl(norm_query))} ${Markup(item.title_hl(norm_query))} ${item.course.title} - ${item.id} • ${item.barcode()} + ${item.smallint()} • ${item.barcode()} ${pagetable(paginator, count, pagerow, pageheader)} -- 2.11.0