Ejemplo n.º 1
0
def library_requests(item_subtype, item_key):
	# 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 = ''
	cur_user = current_user()
	if not cur_user:
		logging.info("there is not a user logged in")
		#return "<a href='%s' >Login</a>" %users.create_login_url(dest_url=url_for('library_requests',ISBN=ISBN))
		
	if request.method == 'GET':
		#check the database to see if the item is in the user's library
		item = Item.get_by_key(item_type,item_key)
		if item:
			if cur_user.get_book(item_subtype,item):
				return item.title
			else:
				return "You do not have this item in your library"
		else:
			return "This item was not found"
	elif request.method == 'POST':
		#add the item to the user's library
		#If not found, add it to the cache, then to the user's library
		item = Item.get_by_key(item_type,item_key)

		if not item:
			return "Item " + item_key + " was not found"
		else:
			if cur_user.get_item(item_subtype,item):
				return "This item is already in your library"
			cur_user.add_item(item_subtype, item)
			return "Item " + item_key + " was added to your library"
	elif request.method == 'DELETE':	
		#remove the item from the user's library
		item = Item.get_by_key(item_type,item_key)
		if not item:
			return "Item not found"
		else:
			if cur_user.get_item(item_subtype,item):
				cur_user.remove_item(item_subtype,item)
			return "Successfully deleted " + item_key + " from your library"
	else:
		#this should never be reached
		return "Error: http request was invalid"
Ejemplo n.º 2
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)
Ejemplo n.º 3
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"})
Ejemplo n.º 4
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)