def user_page(member_id): user_info = con.get_user_info(member_id) user_reviews = con.get_user_reviews(member_id) reviews_count = con.get_reviews_count_for_user(member_id)['count'] member_page = True if 'username' in session: member_to_login = con.check_registered_user(session['username']) login_username = session['username'] user_role = con.get_role_for_user(session['username'])['role'] return render_template('member-page.html', user_info=user_info, user_reviews=user_reviews, reviews_count=reviews_count, member_to_login=member_to_login, member_page=True, login_username=login_username, user_role=user_role) else: return render_template('member-page.html', user_info=user_info, user_reviews=user_reviews, reviews_count=reviews_count, member_page=False)
def show_my_books(): utl.get_list_of_titles_rented_per_member(session) BOOKS_HEADINGS = [ 'Rented ID', 'Book ID', 'Title', 'Author', 'Published Date', 'ISBN', 'To Return In', 'Return Book' ] if 'username' in session: login_username = session['username'] member_to_login = con.check_registered_user(session['username']) member_page = True member_full_name = con.get_user_full_name(session['username']) user_role = con.get_role_for_user(session['username'])['role'] username = session['username'] books_for_member = con.get_books_for_member(username) return render_template('my-books.html', books_for_member=books_for_member, books_headings=BOOKS_HEADINGS, member_to_login=member_to_login, member_page=member_page, member_full_name=member_full_name, login_username=session['username'], user_role=user_role)
def login(): BOOKS_HEADINGS = [ 'ID', 'Title', 'Author', 'Published Date', 'ISBN', 'Copies', 'Status' ] all_books = con.get_all_books() member_page = False is_member = False new_sort_options = { "book_id": "", "title": "", "author": "", "ASC": "", "DESC": "" } if request.method == 'POST': member_to_login = con.check_registered_user(request.form['username']) if len(member_to_login) > 0: is_member = utl.verify_password(request.form['password'], member_to_login[0]['password']) if is_member: member_page = True session['username'] = request.form['username'] user_role = con.get_role_for_user(session['username'])['role'] member_full_name = con.get_user_full_name(session['username']) return render_template('books.html', member_to_login=member_to_login, books_headings=BOOKS_HEADINGS, all_books=all_books, member_page=member_page, member_full_name=member_full_name, user_role=user_role, new_sort_options=new_sort_options) else: return render_template('login.html', is_member=is_member) else: return render_template('login.html', is_member=is_member) return render_template('login.html')
def get_book_info(book_id: int): voting_enabled = True reviewers_ids = [] selected_book_id = con.get_book_by_id(book_id)['book_id'] reviewers_for_book = con.get_reviewers_for_book(selected_book_id) for reviewer in reviewers_for_book: reviewers_ids.append(reviewer['member_id']) member_page = False reviews = con.get_book_reviews(book_id) selected_book = con.get_all_info_for_selected_book(book_id) positive_reviews = utl.calculate_vote_percentage( selected_book['votes_up'], selected_book['votes_down']) if 'username' in session: login_username = session['username'] member_id = con.get_member_id_by_username(login_username)['member_id'] reviewer_member_id = con.get_member_id_by_username_from_review( member_id)['member_id'] member_to_login = con.check_registered_user(session['username']) member_page = True member_full_name = con.get_user_full_name(session['username']) user_role = con.get_role_for_user(session['username'])['role'] return render_template('book-info.html', selected_book=selected_book, member_page=member_page, member_full_name=member_full_name, member_to_login=member_to_login, reviewers_ids=reviewers_ids, positive_reviews=positive_reviews, reviews=reviews, login_username=login_username, reviewer_member_id=reviewer_member_id, user_role=user_role) else: return render_template('book-info.html', reviews=reviews, selected_book=selected_book, positive_reviews=positive_reviews, member_page=member_page)
def books(): BOOKS_HEADINGS = [ 'ID', 'Title', 'Author', 'Published Date', 'ISBN', 'Copies Available', 'Votes Up', 'Votes Down', 'Status' ] global sort_options new_sort_options = { "book_id": "", "title": "", "author": "", "ASC": "", "DESC": "" } member_page = False sorting_option = "book_id" sorting_order = "ASC" if 'username' in session: login_username = session['username'] utl.get_list_of_titles_rented_per_member(session) member_to_login = con.check_registered_user(session['username']) member_full_name = con.get_user_full_name(session['username']) member_page = True user_role = con.get_role_for_user(session['username'])['role'] titles = utl.get_list_of_titles_rented_per_member(session) new_sort_options = { "book_id": "", "title": "", "author": "", "ASC": "", "DESC": "" } if request.method == "POST": if 'sort' in request.form: sorting_option = request.form['sort'] if 'order' in request.form: sorting_order = request.form['order'] for sort_option in sort_options: for elem in request.form: if sort_option == request.form[elem]: new_sort_options[sort_option] = "selected" break else: new_sort_options[sort_option] = "" all_books = con.sort_books_by_(sorting_option, sorting_order) return render_template('books.html', all_books=all_books, books_headings=BOOKS_HEADINGS, member_to_login=member_to_login, member_page=member_page, member_full_name=member_full_name, titles=titles, login_username=login_username, user_role=user_role, new_sort_options=new_sort_options) if request.method == "POST": sorting_option = request.form['sort'] sorting_order = request.form['order'] sort_options[sorting_option] = "select" sort_options[sorting_order] = "select" all_books = con.sort_books_by_(sorting_option, sorting_order) return render_template('books.html', all_books=all_books, books_headings=BOOKS_HEADINGS, member_page=member_page, new_sort_options=new_sort_options)