Example #1
0
	def return_book(self, bookCopyID):
		"""Return the given book to it's owner

		Arguments:
		bookCopyID: an ID representing a BookCopy object, the book to be returned

		Return Value:
		A message describing the success or failure or the operation
		"""
		from bookout.books.models import BookCopy
		from bookout.activity.models import ConfirmReturn
		bookcopy = BookCopy.get_by_id(int(bookCopyID))

		# verify the bookCopyID was valid
		if(bookcopy == None):
			return "Invalid book ID"
		if(bookcopy.owner == self.key):
			bookcopy.return_book()
			bookcopy.put()
			return "Book successfully returned to your library"
		elif (bookcopy.borrower == self.key):
			notification = ConfirmReturn(useraccount=bookcopy.owner,book=bookcopy.key)
			notification.put()
			return "Notice sent to owner, awaiting their confirmantion"
		else:
			return "You are not the owner of this book, nor are you borrowing it"
Example #2
0
	def change_due_date(self, bookCopyID, newDueDate):
		"""Update the date that a book is due

		Arguments:
		bookCopyID: an ID representing a BookCopy object, the book to be returned
		newDueDate: a string representing the new due date of the book

		Return Value:
		A message describing the success or failure or the operation
		"""
		from bookout.books.models import BookCopy
		from bookout.activity.models import DueDateExtension
		bookcopy = BookCopy.get_by_id(int(bookCopyID))
		new_date = datetime.datetime.strptime(newDueDate, '%Y-%m-%d')

		if(bookcopy == None):
			return "Invalid book ID"
		if(bookcopy.owner == self.key):
			bookcopy.update_due_date(new_date)
			bookcopy.put()
			return "Due date successfully updated"
		elif (bookcopy.borrower == self.key):
			import datetime
			notification = DueDateExtension(useraccount=bookcopy.owner,book=bookcopy.key,due_date=new_date)
			notification.put()
			return "Request sent to owner"
		else:
			return "You are not the owner of this book, nor are you borrowing it"
Example #3
0
	def borrow_book(self, bookID, lenderID, due_date = None):
		"""Borrow a book from another user

		Arguments:
		bookID: an ID representing the bookCopy object that will be borrowed
		lenderID: an ID representing the user that will lend the book
		due_date: the date the book should be returned, 
			if none is given the default for the lender is used

		Return value:
		A string describing the success or failure of the operation
		"""
		from bookout.books.models import BookCopy
		bookCopy = BookCopy.get_by_id(bookID)

		# check to see if the book copy is valid
		if(bookCopy == None):
			return "Invalid book ID"
		if(bookCopy.owner.id() != lenderID):
			return "That user does not own this book"
		if(bookCopy.borrower != None):
			return "That book is not avaiable to be lent out"

		bookCopy.lend(self.key.id(), due_date)
		bookCopy.put()
		return "Book successfully borrowed"