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',
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)
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(
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)
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)
?>
py:with="avail, status = item.describe_physical_item_status()">
<th>Status</th><td><div class="${avail and 'available' or 'unavailable'}">${status}</div></td>
</tr>
+ <tr py:if="smallint">
+ <th>Small Number</th><td>${smallint}</td>
+ </tr>
<tr py:if="item.url"><th>URL</th><td><a href="${item.url}">${item.url}</a></td></tr>
</table>
<div py:if="item.item_type=='ELEC'">
<td>${Markup(item.author_hl(norm_query))}</td>
<td><a href="${item.item_url('meta')}">${Markup(item.title_hl(norm_query))}</a></td>
<td><a href="${item.course.course_url()}">${item.course.title}</a></td>
- <td><span py:if="item.item_type=='PHYS'">${item.id} • ${item.barcode()}</span></td>
+ <td><span py:if="item.item_type=='PHYS'">${item.smallint()} • ${item.barcode()}</span></td>
</span>
${pagetable(paginator, count, pagerow, pageheader)}