Exemple #1
0
def book_form(request, name):
  book = Book.query(Book.name==name).get()
  if request.method == 'POST':
    form = BookForm(request.POST, instance=book)
    if form.is_valid():
      form.save()
      return redirect('/books/')
  else:
    form = BookForm(instance=book)
  return render(request, 'book_form.html', {'form': form})
Exemple #2
0
def view_library():
	useraccount = flaskext.login.current_user
	if not useraccount:
		return jsonify({"Error":"User not signed in"})

	books = {}
	i = 0
	for copy in useraccount.get_library():
		book = Book.query(Book.key == copy.book).get()
		books[i] = book.to_dict()
		i += 1
	return jsonify(JsonIterable.dict_of_dict(books))
Exemple #3
0
def get_my_book_list():
	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('manage_library'))

	books = {}
	counter = 0
	for copy in cur_user.get_library():
		book = Book.query(Book.key == copy.book).get()
		books[counter] = book.to_dict()
		counter += 1
	return jsonify(JsonIterable.dict_of_dict(books))
Exemple #4
0
def discover():
	user = current_user()
	booklist = []
	string = ""
	for connection in user.get_connections():
		u = UserAccount.getuser(connection.id())
		for copy in u.get_library():
			book = Book.query(Book.key == copy.book).get()
			booklist.append(book)
	#Sort booklist alphabetically, with title as the primary sort key and author as secondary
	booklist.sort(key=lambda book: book.author.lower())
	booklist.sort(key=lambda book: book.title.lower())
	
	return render_response('discover.html',books=booklist)
Exemple #5
0
def book_due_reminders():
	count = 0
	"""find all the books due tomorrow and send reminder emails"""
	books = BookCopy.query(BookCopy.due_date==date.today() + timedelta(days=1)).fetch()
	for book in books:
		count += 1
		owner = UserAccount.query(UserAccount.key==book.owner).get()
		mail.send_mail(sender=owner.email,
			to=UserAccount.query(UserAccount.key==book.borrower).get().email,
			subject="Book Due Soon",
			body="""Hey, remember that book you borrowed on Bookout from me, '%s'? Please get it back to me by tomorrow.
			
Thanks!
%s"""%(Book.query(Book.key==book.book).get().title,owner.name))
	return "%s reminders were sent out" %count
Exemple #6
0
def library():
	booklist = []
	useraccount = current_user()
	for copy in useraccount.get_library():
		book = Book.query(Book.key == copy.book).get()
		book.title = book.title
		book.escapedtitle = re.escape(book.title)
		if copy.borrower is None:
			book.available = True
		else:
			book.available = False
		booklist.append(book)
	#Sort booklist alphabetically, with title as the primary sort key and author as secondary
	booklist.sort(key=lambda book: book.author.lower())
	booklist.sort(key=lambda book: book.title.lower())
		
	return render_response('managelibrary.html', myBooks=booklist)
Exemple #7
0
def profile(userID):
	profile_user = UserAccount.get_by_id(int(userID))
	user = current_user()
	if not profile_user:
		return render_response('invalidprofile.html')
	if user.is_connected(profile_user):
		library = []
		for copy in profile_user.get_library():
			book = Book.query(Book.key == copy.book).get()
			library.append(book)
			if copy.borrower is None:
				book.available = True
			else:
				book.available = False
			book.copyid = copy.key.id()
		return render_response('profile.html',profile_user=profile_user,library=library)
	return render_response('invalidprofile.html')
Exemple #8
0
def books(request):
  return render(request, 'books.html', {'books': Book.query()})