Esempio n. 1
0
def request_to_borrow(lenderID, itemCopyID):
	emailText = []
	emailText.append("You have received the following message from " + current_user().name + ", a Sharing Commons user.\n----\n\n")
	emailText.append(request.data)
	emailText.append("\n\n----\nReply to this message to send an email to " + current_user().name + " and set up the exchange. Once you've lent the item, visit beta.sharingcommons.com to confirm lending the item. "  + current_user().name + " will receive an email when the item is due")
	emailBody = ''.join(emailText)
	
	# Request item
	try:
		borrower = current_user()
		lender = UserAccount.getuser(int(lenderID))
		itemCopy = ItemCopy.get_by_id(int(itemCopyID))
		
		rtb1 = RequestToBorrow()
		rtb1.useraccount = lender.key
		rtb1.connection = borrower.key
		rtb1.item = itemCopy.key
		rtb1.put()
		
		wtb1 = WaitingToBorrow()
		wtb1.useraccount = borrower.key
		wtb1.connection = lender.key
		wtb1.item = itemCopy.key
		wtb1.put()
		
	except:
		return jsonify({"result":"error"})
	
	# Send email
	mail.send_mail(sender="Sharing Commons <*****@*****.**>",
			to=lender.name + " <" + lender.email + ">",
			reply_to=borrower.name + " <" + borrower.email + ">",
			subject='Sharing Commons: Request to Borrow "' + Item.query(Item.key == itemCopy.item).get().title + '"',
			body=emailBody)
	return jsonify({"result":"success"})
Esempio n. 2
0
def setup_item_borrow_actions(lenderID, itemCopyID):
	borrower = current_user()
	lender = UserAccount.getuser(int(lenderID))
	itemCopy = ItemCopy.get_by_id(int(itemCopyID))
	
	rtb1 = RequestToBorrow()
	rtb1.useraccount = lender.key
	rtb1.connection = borrower.key
	rtb1.item = itemCopy.key
	rtb1.put()
	
	wtb1 = WaitingToBorrow()
	wtb1.useraccount = borrower.key
	wtb1.connection = lender.key
	wtb1.item = itemCopy.key
	wtb1.put()
	return jsonify({"Message":"OK"})