示例#1
0
def accept_friend(id):
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    friends.accept_friend_request(user_id, id)
    return redirect("/friends/findfriends/" + str(id))
示例#2
0
def book_progress(id):
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    book = books.find_book_by_id(id)
    events = bookshelf.find_book_events(user_id, id)
    latest = events[0]
    return render_template("bookshelf_book.html", book=book, events=events, latest=latest)
示例#3
0
def findfriendsbyid(id):
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    result = friends.find_connection(user_id, id)
    if result[1] == user_id:
        result = ("you", result[1], result[2])
    return render_template("user.html", user=result)
示例#4
0
def add_to_bookshelf():
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    book_id = request.form["book_id"]
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    bookshelf.add_new_book_event(user_id, book_id, 0)
    return redirect("/search/findbooks/" + book_id)
示例#5
0
def send_friend_request(id):
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    if friends.check_if_already_friends(user_id, id) == None:
        friends.send_friend_request(user_id, id)
    return redirect("/friends/findfriends/" + str(id))
示例#6
0
def remove_bookshelf_book():
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    book_id = request.form["book_id"]
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    bookshelf.remove_from_bookshelf(user_id, book_id)
    return redirect("/bookshelf")
示例#7
0
def index():
    friend_events = []
    if session.get("username") is not None:
        username = session["username"]
        user_id = users.get_user_id_by_username(username)
        ratings = friends.get_friends_reviews(user_id)
        progress_updates = friends.get_friends_updates(user_id)
        friend_events = events.concatenate_event_lists(ratings, progress_updates)
    return render_template("index.html", events = friend_events)
示例#8
0
def update_progress():
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    book_id = request.form["book_id"]
    progress = request.form["progress"]
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    bookshelf.add_new_book_event(user_id, book_id, progress)
    return redirect("/bookshelf/progress/" + book_id)
示例#9
0
def add_review(id):
    if session["csrf_token"] != request.form["csrf_token"]:
        abort(403)
    book_id = id
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    review = request.form["review"]
    star_rating = request.form["stars"]
    already_exists = books.check_if_already_rated(user_id, id) != None
    books.add_review(user_id, book_id, star_rating, review, already_exists)
    return redirect("/search/findbooks/" + str(id))
示例#10
0
def find_books_id(id):
    book = books.find_book_by_id(id)
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    info = bookshelf.check_if_in_bookshelf(user_id, id)
    review = books.check_if_already_rated(user_id, id)
    if review == None:
        review = (0, 0, "", 0)

    ratings = books.find_reviews_by_book_id(id)

    return render_template("book.html", book=book, review=review, info=info, ratings=ratings)
示例#11
0
def get_pending_for_player(username):
	user_id = users.get_user_id_by_username(username)

	games = []
	for game in db.Game.objects.filter(
			('scheduled_time__isnull', 0), ('white_player_id', user_id), ('result', '?-?')).values():
		games.append(expand_foreign_keys_names(game))
	for game in db.Game.objects.filter(
			('scheduled_time__isnull', 0), ('black_player_id', user_id), ('result', '?-?')).values():
		games.append(expand_foreign_keys_names(game))
		
	return games
示例#12
0
def friends_page():
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    ok = []
    sent = []
    waiting = []
    for i in friends.find_all_friends(user_id):
        if i[2] == 'ok':
            ok.append(i)
        if i[2] == 'sent':
            sent.append(i)
        if i[2] == 'waiting':
            waiting.append(i)
    return render_template("friends.html", ok = ok, sent = sent, waiting = waiting)
示例#13
0
def go_to_bookshelf():
    username = session["username"]
    user_id = users.get_user_id_by_username(username)
    shelved_books = bookshelf.find_all_books(user_id)
    return render_template("bookshelf.html", books=shelved_books)