IMPORTANT:
* finish the physical-item received workflow.
- * how to model 'received' in the database?
+ * nicer error-message if smallint already taken.
* if someone has item checked out, show due date/time on item-about page.
* does 'move to new heading' show up in the right places? Should be like 'edit'.
-* a short-number for physical items. Sort of a barcode, but intended
- for easier communicatinon between patrons and staff.
- (Update views.search() when this is in place)
-
* Import of reserves data from Leddy voyager. Laurentian, others?
* People should be able to register themselves into open courses.
# an optional small-integer used as a human-shareable barcode by some institutions.
smallint = m.IntegerField(blank=True, null=True)
+ def __unicode__(self):
+ return '%s (%s) %s' % (self.barcode, self.smallint, self.departed and 'gone' or 'live')
def save(self, force_insert=False, force_update=False):
# Must ensure that barcode is unique for non-departed items. Same with smallint
- try:
- unique_thing = 'barcode'
- already = PhysicalObject.objects.exclude(pk=self.id).get(departed=None)
- unique_thing = 'smallint'
- if self.smallint:
- already = PhysicalObject.objects.exclude(pk=self.id).get(smallint=self.smallint)
- except PhysicalObject.DoesNotExist:
- super(PhysicalObject, self).save(force_insert, force_update)
- else:
- raise AssertionError, '%s is not unique in active PhysicalObject collection.' % unique_thing
+ live_objs = PhysicalObject.objects.exclude(pk=self.id).filter(departed=None)
+ same_barcode = live_objs.filter(barcode=self.barcode)
+ assert not same_barcode, \
+ 'Barcode is not unique in active PhysicalObject collection.'
+ if self.smallint:
+ same_smallint = live_objs.filter(smallint=self.smallint)
+ assert not same_smallint, \
+ 'Small Number is not unique in active PhysicalObject collection.'
+ super(PhysicalObject, self).save(force_insert, force_update)
@classmethod
def by_smallint(cls, smallint):
barcode = request.POST.get('barcode', '').strip()
assert barcode
smallint = request.POST.get('smallint', '').strip() or None
- phys = models.PhysicalObject(barcode=barcode,
- receiver = request.user,
- smallint = smallint)
- phys.save()
+ try:
+ phys = models.PhysicalObject(barcode=barcode,
+ receiver = request.user,
+ smallint = smallint)
+ phys.save()
+ except Exception, e:
+ return simple_message(_('Error'), repr(e), go_back=True)
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()
- return simple_message(_('Matches saved.'), '', go_back=False)
+ return g.render('phys/mark_arrived_outcome.xhtml')