def _add_friend(): if not check_login(session): return redirect("/login") try: add_friend(db, session.get("username"), request.form["name"]) except Exception as e: flash(str(e)) return redirect("/friends")
def _add_title(): if not check_login(session): return redirect("/login") friend_list = list() for friend in get_friends(db, session.get("username")): friend_list.append(friend) return render_template("addtitle.html", statuses=get_statuses(db), friends=friend_list)
def _add_status(): if not check_login(session): return redirect("/login") status = request.form["name"] try: add_status(db, status) except Exception as e: flash(str(e)) return redirect("/status")
def newtitle(): if not check_login(session): return redirect("/login") try: add_title(db, request.form["author"], request.form["name"], request.form["genre"], request.form["status"]) add_book(db,request.form["author"],request.form["name"],request.form["genre"],\ request.form["status"],session.get("username"),request.form["friend"]) except Exception as e: flash(str(e)) else: flash('Book added') return redirect("/addtitle")
def change_status(): if not check_login(session): return redirect("/login") if request.form["action"] == "change": try: change_book_status(db, session.get("username"), request.form, request.form["status"]) change_book_holder(db, session.get("username"), request.form, request.form["friend"]) except Exception as e: flash(str(e)) elif request.form["action"] == "delete": try: delete_book(db, session.get("username"), request.form) except Exception as e: flash(str(e)) return redirect("/")
def _edit_list(): if not check_login(session): return redirect("/login") try: books = get_books_for_user_and_status(db, session.get("username"), "") except DatabaseException as e: return render_template("index.html", message=e) except Exception as e: return render_template("index.html", message="Unexpected error: " + str(e)) loaned = list() for book in books: if book[2] == "Loaned": loaned.append(book) friend_list = list() for friend in get_friends(db, session.get("username")): friend_list.append(friend) return render_template("edit_book_statuses.html",message="Welcome "+session.get("username"),\ books=books,loaned=loaned,statuses=get_statuses(db),friends=friend_list)
def _friends(): if not check_login(session): return redirect("/login") friends = get_friends(db, session.get("username")) return render_template("friends.html", friends=friends)
def _status(): if not check_login(session): return redirect("/login") return render_template("statuses.html", statuses=get_statuses(db))