def lend_thing(username, thing_id, to_user): try: thing = Thing.get(thing_id) except ResourceNotFound: print 'Thing not found' return lending = Lending(thing=thing_id, owner=username, to_user=to_user) lending.save() print lending, 'saved with _id', lending._id
def return_thing(username, lend_id): lending = Lending.get(lend_id) lending.returned = datetime.now() lending.save() print lending, 'saved with _id', lending._id
def callback(line): seq = line['seq'] doc = line['doc'] if doc.get('doc_type', None) == 'Thing': obj = Thing.wrap(doc) elif doc.get('doc_type', None) == 'Lending': obj = Lending.wrap(doc) else: # we also have other types of documents - _design docs return print '{:5d} {:s} {:s}'.format(seq, line['id'], obj)