Example #1
0
	def add_book(self,inBook):
		"""add a personal copy of a book to a user's account
		
		Arguments:
		book - Book object being attached to the User

		Return Value:
		a BookCopy instance that links the User to the Book; None if the Book could not be linked
		"""
		from bookout.books.models import BookCopy
		bookcopy = BookCopy(book=inBook.key,owner=self.key,OLKey=inBook.OLKey)
		if bookcopy.put():
			self.book_count = self.book_count + 1
			self.put()
		return bookcopy
Example #2
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"
Example #3
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 #4
0
	def confirm(self):
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		book = Book.query(Book.key==bookcopy.book).get()
		bookcopy.update_due_date(self.due_date)
		bookcopy.put()
		self.cleanup()
		return "%s has been extended to %s" %(book.title,str(self.due_date))
Example #5
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 #6
0
	def get_lent_books(self):
		"""Get all the books that the user is currently lending to anther user

		Return Value:
		A list of BookCopy objects of all the the books the user is currently lending
		"""
		from bookout.books.models import BookCopy
		return BookCopy.query(BookCopy.owner==self.key,BookCopy.borrower!=None).fetch()
Example #7
0
	def get_borrowed_books(self):
		"""Get all the books that the user is currently borrowing from anther user

		Return Value:
		A list of BookCopy objects of all the the books the user is currently borrowing
		"""
		from bookout.books.models import BookCopy
		return BookCopy.query(BookCopy.borrower==self.key).fetch()
Example #8
0
	def confirm(self):
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		other = UserAccount.query(UserAccount.key==bookcopy.borrower).get()
		book = Book.query(Book.key==bookcopy.book).get()
		bookcopy.return_book()
		bookcopy.put()
		self.cleanup()
		return "%s has been returned to your library" %(book.title)
Example #9
0
	def get_library(self):
		"""retrieve the user's library
		
		Return value:
		list of BookCopy objects owned by the user
		"""
		from bookout.books.models import BookCopy
		return BookCopy.query(BookCopy.owner==self.key).fetch()
Example #10
0
	def get_network_books(self):
		"""Get all the books owned by users connected to this owned

		Return value:
		an array will all the BookCopy objects belonging to connected users

		"""
		from bookout.books.models import BookCopy
		return BookCopy.query(BookCopy.owner.IN(self.get_connections())).fetch()
Example #11
0
	def reject(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		book = Book.query(Book.key==bookcopy.book).get()
		self.cleanup()
		
		otherAction = RequestToBorrow.query(RequestToBorrow.book == bookcopy.key and RequestToBorrow.useraccount == other.key).get()
		otherAction.cleanup()
		
		return "Request cancelled"
Example #12
0
	def reject(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		book = Book.query(Book.key==bookcopy.book).get()
		self.cleanup()

		otherAction = WaitingToBorrow.query(WaitingToBorrow.book == bookcopy.key and WaitingToBorrow.useraccount == other.key).get()
		otherAction.cleanup()
		
		return "You have denied %s permission to borrow %s" %(other.name,book.title)
Example #13
0
	def get_book(self,book):
		"""retrieve the user's copy of a particular book
		
		Arguments:
		book - the Book being retrieved

		Return value:
		the user's BookCOpy object associated with the provided Book; None if the user does not own book
		"""
		from bookout.books.models import BookCopy
		mybook = BookCopy.query(BookCopy.book==book.key,BookCopy.owner==self.key).get()
		return mybook
Example #14
0
	def confirm(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		book = Book.query(Book.key==bookcopy.book).get()
		
		due_date = None
		cur_user = UserAccount.query(UserAccount.key==self.useraccount).get()
		cur_user.lend_book(int(bookcopy.key.id()), int(other.key.id()), due_date)
		
		self.cleanup()
		
		otherAction = WaitingToBorrow.query(WaitingToBorrow.book == bookcopy.key and WaitingToBorrow.useraccount == other.key).get()
		otherAction.cleanup()
		
		return "You have agreed to lend %s to %s" %(book.title,other.name)
Example #15
0
	def remove_book(self,book):
		"""delete a user's copy of a book
		
		Arguments:
		book - Book object that is to be removed

		Return value:
		the BookCopy instance that was just deleted; None if the BookCopy was not found
		"""
		from bookout.books.models import BookCopy
		bookcopy = BookCopy.query(BookCopy.book==book.key,BookCopy.owner==self.key).get()
		if bookcopy:
			bookcopy.key.delete()
			self.book_count = self.book_count - 1
			self.put()
		return bookcopy
Example #16
0
	def confirm(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		book = Book.query(Book.key==bookcopy.book).get()
		print "You have accepted a connection request from %s" %(other.name)
Example #17
0
	def text(self):
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		other = UserAccount.query(UserAccount.key==bookcopy.borrower).get()
		book = Book.query(Book.key==bookcopy.book).get()
		return "%s reported checking in '%s'" %(other.name,book.title)
Example #18
0
	def reject(self):
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		other = UserAccount.query(UserAccount.key==bookcopy.borrower).get()
		book = Book.query(Book.key==bookcopy.book).get()
		self.cleanup()
		return "Recorded that %s didn't return %s" %(other.name,book.title)
Example #19
0
	def text(self):
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		other = UserAccount.query(UserAccount.key==bookcopy.borrower).get()
		book = Book.query(Book.key==bookcopy.book).get()
		return "%s wants to extend the due date of '%s' to %s?" %(other.name,book.title,str(self.due_date))
Example #20
0
	def text(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		book = Book.query(Book.key==bookcopy.book).get()
		return "%s has requested to borrow '%s'" %(other.name,book.title)
Example #21
0
	def text(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		bookcopy = BookCopy.query(BookCopy.key==self.book).get()
		book = Book.query(Book.key==bookcopy.book).get()
		return "You have requested to borrow '%s' from %s" %(book.title,other.name)