Exemple #1
0
	def confirm(self):
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		item = Item.query(Item.key==itemcopy.item).get()
		itemcopy.update_due_date(self.due_date)
		itemcopy.put()
		self.cleanup()
		return "%s has been extended to %s" %(item.title,str(self.due_date))
Exemple #2
0
	def confirm(self):
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		other = UserAccount.query(UserAccount.key==itemcopy.borrower).get()
		item = Item.query(Item.key==itemcopy.item).get()
		itemcopy.return_item()
		itemcopy.put()
		self.cleanup()
		return "%s has been returned to your library" %(item.title)
Exemple #3
0
    def get_lent_items(self):
        """Get all the items that the user is currently lending to anther user

		Return Value:
		A list of ItemCopy objects of all the the items the user is currently lending
		"""
        from src.items.models import ItemCopy

        return ItemCopy.query(ItemCopy.owner == self.key, ItemCopy.borrower != None).fetch()
Exemple #4
0
    def get_library(self):
        """retrieve the user's library
		
		Return value:
		list of ItemCopy objects owned by the user
		"""
        from src.items.models import ItemCopy

        return ItemCopy.query(ItemCopy.owner == self.key).fetch()
Exemple #5
0
    def get_network_items(self):
        """Get all the items owned by users connected to this owned

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

		"""
        from src.items.models import ItemCopy

        return ItemCopy.query(ItemCopy.owner.IN(self.get_connections())).fetch()
Exemple #6
0
	def reject(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		item = Item.query(Item.key==itemcopy.item).get()
		self.cleanup()
		
		otherAction = RequestToBorrow.query(RequestToBorrow.item == itemcopy.key and RequestToBorrow.useraccount == other.key).get()
		otherAction.cleanup()
		
		return "Request cancelled"
Exemple #7
0
	def reject(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		item = Item.query(Item.key==itemcopy.item).get()
		self.cleanup()

		otherAction = WaitingToBorrow.query(WaitingToBorrow.item == itemcopy.key and WaitingToBorrow.useraccount == other.key).get()
		otherAction.cleanup()
		
		return "You have denied %s permission to borrow %s" %(other.name,item.title)
Exemple #8
0
def movie_info(RTKey):
	itemMovie = Item.get_by_key("movie",RTKey)
	movie = itemMovie.to_dict()
	# Check if user owns book and pass itemCopy object
	if current_user().is_authenticated():
		itemCopy = ItemCopy.query(ItemCopy.item==itemMovie.key,ItemCopy.owner==current_user().key).fetch()
		if itemCopy:
			movieCopy = itemCopy[0]
		else:
			movieCopy = None
	else:
		movieCopy = None
	return render_response('itemdetail.html', item=movie, itemCopy=movieCopy)
Exemple #9
0
def item_due_reminders():
	count = 0
	"""find all the items due tomorrow and send reminder emails"""
	items = ItemCopy.query(ItemCopy.due_date==date.today() + timedelta(days=1)).fetch()
	for item in items:
		count += 1
		owner = UserAccount.query(UserAccount.key==item.owner).get()
		mail.send_mail(sender=owner.email,
			to=UserAccount.query(UserAccount.key==item.borrower).get().email,
			subject="Item Due Soon",
			body="""The following item is due to be returned tomorrow: '%s'.
			
Please return it to %s"""%(Item.query(Item.key==item.item).get().title,owner.name))
	return "%s reminders were sent out" %count
Exemple #10
0
	def confirm(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		item = Item.query(Item.key==itemcopy.item).get()
		
		due_date = None
		cur_user = UserAccount.query(UserAccount.key==self.useraccount).get()
		cur_user.lend_item(int(itemcopy.key.id()), int(other.key.id()), due_date)
		
		self.cleanup()
		
		otherAction = WaitingToBorrow.query(WaitingToBorrow.item == itemcopy.key and WaitingToBorrow.useraccount == other.key).get()
		otherAction.cleanup()
		
		return "You have agreed to lend %s to %s" %(item.title,other.name)
Exemple #11
0
    def get_item(self, item_subtype, item):
        """retrieve the user's copy of a particular item
		
		Arguments:
		item - the Item being retrieved

		Return value:
		the user's ItemCopy object associated with the provided Item; None if the user does not own item
		"""
        from src.items.models import ItemCopy

        myitem = ItemCopy.query(
            ItemCopy.item == item.key, ItemCopy.owner == self.key, ItemCopy.item_subtype == item_subtype
        ).get()
        return myitem
Exemple #12
0
    def get_borrowed_items(self):
        """Get all the items that the user is currently borrowing from anther user

		Return Value:
		A list of ItemCopy objects of all the the items the user is currently borrowing
		"""
        from src.items.models import ItemCopy

        itemList = ItemCopy.query(ItemCopy.borrower == self.key).fetch()
        # Remove manually lent items (items being lended to the user's self)
        # They appear here because the borrower and lender is set to the user's self
        borrowedItems = []
        for item in itemList:
            if not item.manual_borrower_name:
                borrowedItems.append(item)
        return borrowedItems
Exemple #13
0
def star_rating(item_subtype, item_key, star_rating):
	# Get Item
	# Infer item_type
	if item_subtype in ('book', 'ebook', 'audiobook'):
		item_type = 'book'
	elif item_subtype in ('dvd', 'bluray'):
		item_type = 'movie'
	else:
		item_type = ''
	item = Item.get_by_key(item_type,item_key)
	
	# Get ItemCopy
	itemCopy = ItemCopy.query(ItemCopy.item==item.key,ItemCopy.owner==current_user().key,ItemCopy.item_subtype==item_subtype).get()
	if itemCopy.update_star_rating(star_rating):
		return jsonify({"result":"success"})
	else:
		return jsonify({"result":"error"})
Exemple #14
0
def book_info(OLKey):
	# Pass book object to template
	itemBook = Item.get_by_key("book",OLKey)
	book = itemBook.to_dict()
	# Determine if the user owns this book
	# Find all connections who own this book and get the status for each
	# Find out any pending actions regarding this book
	# Find any current loans or borrow of this book
	
	# Check if user owns book and pass itemCopy object
	if current_user().is_authenticated():
		itemCopy = ItemCopy.query(ItemCopy.item==itemBook.key,ItemCopy.owner==current_user().key).fetch()
		if itemCopy:
			bookCopy = itemCopy[0]
		else:
			bookCopy = None
	else:
		bookCopy = None
	return render_response('itemdetail.html',item=book,itemCopy=bookCopy)
Exemple #15
0
    def remove_item(self, item_subtype, item):
        """delete a user's copy of a item
		
		Arguments:
		item - Item object that is to be removed

		Return value:
		the ItemCopy instance that was just deleted; None if the ItemCopy was not found
		"""
        from src.items.models import ItemCopy

        itemcopy = ItemCopy.query(
            ItemCopy.item == item.key, ItemCopy.owner == self.key, ItemCopy.item_subtype == item_subtype
        ).get()
        if itemcopy:
            itemcopy.key.delete()
            self.item_count = self.item_count - 1
            self.put()
        return itemcopy
Exemple #16
0
	def confirm(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		item = Item.query(Item.key==itemcopy.item).get()
		print "You have accepted a connection request from %s" %(other.name)
Exemple #17
0
	def text(self):
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		other = UserAccount.query(UserAccount.key==itemcopy.borrower).get()
		item = Item.query(Item.key==itemcopy.item).get()
		return "%s reported checking in '%s'" %(other.name,item.title)
Exemple #18
0
	def reject(self):
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		other = UserAccount.query(UserAccount.key==itemcopy.borrower).get()
		item = Item.query(Item.key==itemcopy.item).get()
		self.cleanup()
		return "Recorded that %s didn't return %s" %(other.name,item.title)
Exemple #19
0
	def text(self):
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		other = UserAccount.query(UserAccount.key==itemcopy.borrower).get()
		item = Item.query(Item.key==itemcopy.item).get()
		return "%s wants to extend the due date of '%s' to %s?" %(other.name,item.title,str(self.due_date))
Exemple #20
0
	def text(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		item = Item.query(Item.key==itemcopy.item).get()
		return "%s has requested to borrow '%s'" %(other.name,item.title)
Exemple #21
0
	def text(self):
		other = UserAccount.query(UserAccount.key==self.connection).get()
		itemcopy = ItemCopy.query(ItemCopy.key==self.item).get()
		item = Item.query(Item.key==itemcopy.item).get()
		return "You have requested to borrow '%s' from %s" %(item.title,other.name)