def get_borrowed_items(): cur_user = current_user() borrowedItems = [] for itemcopy in cur_user.get_borrowed_books(): if not itemcopy.manual_borrower_name: #Don't include items the user is manually lending (they would come up because the borrower is set to the user) item = Item.get_by_id(itemcopy.item.id()) owner = UserAccount.get_by_id(itemcopy.owner.id()) itemInfo = dict() itemInfo["title"] = item.title itemInfo["author"] = item.author itemInfo["copyID"] = itemcopy.key.id() itemInfo["ownerId"] = itemcopy.owner.id() itemInfo["owner"] = owner.name itemInfo["due_date"] = str(itemcopy.due_date) borrowedItems.append(itemInfo) return jsonify({"borrowedItems":borrowedItems})
def get_lent_items(): cur_user = current_user() lentItems = [] for itemcopy in cur_user.get_lent_books(): item = Item.get_by_id(itemcopy.item.id()) borrower = UserAccount.get_by_id(itemcopy.borrower.id()) itemInfo = dict() itemInfo["title"] = item.title itemInfo["author"] = item.author itemInfo["copyID"] = itemcopy.key.id() itemInfo["borrowerId"] = itemcopy.borrower.id() itemInfo["borrower"] = borrower.name itemInfo["due_date"] = str(itemcopy.due_date) if itemcopy.manual_borrower_name: itemInfo["manual_borrower_name"] = itemcopy.manual_borrower_name itemInfo["manual_borrower_email"] = itemcopy.manual_borrower_email lentItems.append(itemInfo) return jsonify({"lentItems":lentItems})