def reviews_index(): if 'page' in flask.request.args: page = int(flask.request.args['page']) else: page = 1 if page <= 0: flask.abort(404) with easypg.cursor() as cur: total_pages = reviews.get_total_pages(cur) with easypg.cursor() as cur: review_info = reviews.get_all_reviews(cur, page) if page > 1: prevPage = page - 1 else: prevPage = None if page == total_pages: nextPage = None else: nextPage = page + 1 return flask.render_template('review_list.html', reviews=review_info, page=page, totalPages=total_pages, nextPage=nextPage, prevPage=prevPage)
def add_review(bid): errors = [] if flask.request.method == 'POST': app.logger.info('Received new data for review from user_id %s: %s', flask.ext.login.current_user.id, flask.request.form) with easypg.cursor() as cur: entry_status, messages, review_id = reviews.add_review( cur, bid, flask.ext.login.current_user.id, flask.request.form) app.logger.info("Review submitted %s - %s - %s", entry_status, messages, review_id) if entry_status: for message in messages: flask.flash(message) return flask.redirect( flask.request.args.get("next") or flask.url_for("display_review", rid=review_id)) else: for message in messages: errors.append(message) with easypg.cursor() as cur: book_info = books.get_book(cur, bid, flask.ext.login.current_user.id) # print book_info['user_rating'] if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("reviews_index") return flask.render_template("review_add_form.html", book_info=book_info, error=errors, next=next)
def lists_index(): if "page" in flask.request.args: page = int(flask.request.args["page"]) else: page = 1 if page <= 0: flask.abort(404) with easypg.cursor() as cur: total_pages = lists.get_total_pages(cur) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): list_info = lists.get_all_lists(cur, page, flask.session["user_id"]) else: list_info = lists.get_all_lists(cur, page, None) if page > 1: prevPage = page - 1 else: prevPage = None if page == total_pages: nextPage = None else: nextPage = page + 1 return flask.render_template( "lists_list.html", lists=list_info, page=page, totalPages=total_pages, nextPage=nextPage, prevPage=prevPage )
def add_review(bid): errors = [] if flask.request.method == "POST": app.logger.info( "Received new data for review from user_id %s: %s", flask.ext.login.current_user.id, flask.request.form ) with easypg.cursor() as cur: entry_status, messages, review_id = reviews.add_review( cur, bid, flask.ext.login.current_user.id, flask.request.form ) app.logger.info("Review submitted %s - %s - %s", entry_status, messages, review_id) if entry_status: for message in messages: flask.flash(message) return flask.redirect(flask.request.args.get("next") or flask.url_for("display_review", rid=review_id)) else: for message in messages: errors.append(message) with easypg.cursor() as cur: book_info = books.get_book(cur, bid, flask.ext.login.current_user.id) # print book_info['user_rating'] if "next" in flask.request.args: next = flask.request.args["next"] else: next = flask.url_for("reviews_index") return flask.render_template("review_add_form.html", book_info=book_info, error=errors, next=next)
def lists_index(): if 'page' in flask.request.args: page = int(flask.request.args['page']) else: page = 1 if page <= 0: flask.abort(404) with easypg.cursor() as cur: total_pages = lists.get_total_pages(cur) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): list_info = lists.get_all_lists(cur, page, flask.session['user_id']) else: list_info = lists.get_all_lists(cur, page, None) if page > 1: prevPage = page - 1 else: prevPage = None if page == total_pages: nextPage = None else: nextPage = page + 1 return flask.render_template('lists_list.html', lists=list_info, page=page, totalPages=total_pages, nextPage=nextPage, prevPage=prevPage)
def edit_book(bid): errors = [] if flask.request.method == 'POST': with easypg.cursor() as cur: edit_status, messages = books.edit_book(cur, bid, flask.request.form) if edit_status: for message in messages: flask.flash(message) return flask.redirect( flask.request.args.get("next") or flask.url_for("display_book", bid=bid)) else: for message in messages: errors.append(message) if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("display_book", bid=bid) with easypg.cursor() as cur: book_info = books.get_book(cur, bid) return flask.render_template("book_edit_form.html", book_info=book_info, error=errors, next=next)
def add_review(bid, uid): uid = flask.session["user_id"] with easypg.cursor() as cur: poster = user.get_user_login(cur, uid) ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') text = flask.request.form['review'] app.logger.info('got review from %s: %s', poster, text) with easypg.cursor() as cur: review.add_review(cur, text, bid, st, uid, poster) return flask.redirect('/books/' + bid)
def print_followees(user_id): if request.method == "GET": if 'page' in request.args: page = int(request.args['page']) else: page = 1 if page <= 0: abort(404) with easypg.cursor() as cur: followees = follows.get_followees(cur, page, user_id) total_pages = follows.get_followee_pg_cnt(cur, user_id) return render_template('followees.html', follow=followees, page=page, total_pages=total_pages, uid=user_id) if page > 1: prevPage = page - 1 else: prevPage = None if page < total_pages: nextPage = page + 1 else: nextPage = None
def print_followers(uid): if 'page' in request.args: page = int(request.args['page']) else: page = 1 if page <= 0: abort(404) id = session['username'] with easypg.cursor() as cur: followers = follows.get_followers(cur, page, id) total_pages = follows.get_follower_pg_cnt(cur, id) return render_template('followers.html', follow=followers, page=page, total_pages=total_pages, user=id) if page > 1: prevPage = page - 1 else: prevPage = None if page < total_pages: nextPage = page + 1 else: nextPage = None
def get_search_results(): if 'q' in request.args: query = request.args['q'] if 'dropdown' in request.args: type = request.args['dropdown'] else: abort(400) books = None authors = None categories = None users = None with easypg.cursor() as cur: if type == "Book": books = queries.search_titles(cur, query) if type == "Author": authors = queries.search_authors(cur, query) if type == "Categories": categories = queries.search_categories(cur, query) if type == "User": users = queries.search_users(cur, query) return render_template('search_results.html', query=query, books=books, users=users, authors=authors, categories=categories)
def login(): with easypg.cursor() as cur: num_users = user.get_user_count(cur) num_friends = friends.count_num_friends(cur) return flask.render_template('login.html', num_users=num_users, num_friends=num_friends)
def dlt_review(uid, rid): with easypg.cursor() as cur: f = request.form for key in f.keys(): remove_review = f.getlist(key)[0] reviews.delete_review(cur, remove_review) return redirect('/users/' + uid + '/reviews')
def find_books_with_tag(tag): uid = flask.session["user_id"] if 'page' in flask.request.args: page = int(flask.request.args['page']) else: page = 1 if page <= 0: flask.abort(404) with easypg.cursor() as cur: book_list = books.get_all_books_with_tag(cur, tag, page) login = user.get_user_login(cur, uid) total = book_list.__len__() if page > 1: prevPage = page - 1 else: prevPage = None nextPage = page + 1 extraPage = 0 remainder = total % 50 if remainder != 0: extraPage = 1 maxPages = int(total / 50) + extraPage return flask.render_template('tagBooks.html', login=login, book_list=book_list, tag_name=tag, total=total)
def list_books_by_pub(pub_name): uid = flask.session["user_id"] if 'page' in flask.request.args: page = int(flask.request.args['page']) else: page = 1 if page <= 0: flask.abort(404) with easypg.cursor() as cur: pub_book_list = books.get_all_books_with_publisher(cur, pub_name, page) login = user.get_user_login(cur, uid) total = pub_book_list.__len__() if page > 1: prevPage = page - 1 else: prevPage = None nextPage = page + 1 extraPage = 0 remainder = total % 50 if remainder != 0: extraPage = 1 maxPages = int(total / 50) + extraPage return flask.render_template('pubBooks.html', login=login, pub_book_list=pub_book_list, publisher=pub_name, total=total)
def get_search_results(): if 'q' in flask.request.args: query = flask.request.args['q'] else: flask.abort(400) if 'page' in flask.request.args: page = int(flask.request.args['page']) else: page = 1 if page <= 0: flask.abort(404) with easypg.cursor() as cur: results, total = search.search_books(cur, query, page) if page > 1: prevPage = page - 1 else: prevPage = None nextPage = page + 1 extraPage = 0 remainder = total % 50 if remainder != 0: extraPage = 1 maxPages = int(total / 50) + extraPage return flask.render_template('search_results.html', query=query, books=results, total=total, resultsPages=maxPages, prevPage=prevPage, nextPage=nextPage, page=page)
def profile_points(profile_id): uid = flask.session['user_id'] with easypg.cursor() as cur: login = user.get_user_login(cur, uid) profile_login = user.get_user_login(cur, profile_id) friend_points = friends.num_friends_targeting_user(cur, profile_id) quote_points = 0 #quote_points = quote.get_quote_points_for_user(cur, profile_id) review_points = review.get_num_reviews_for_user(cur, profile_id) book_points = books.num_unique_books_read(cur, profile_id) comment_points = comments.get_comment_points_for_user(cur, profile_id) total_points = 0 total_points = total_points + friend_points total_points = total_points + review_points total_points = total_points + book_points #total_points = total_points + quote_points total_points = total_points + comment_points return flask.render_template('points_page.html', login=login, profile_id=profile_id, total_points=total_points, friend_points=friend_points, book_points=book_points, profile_login=profile_login, quote_points=quote_points, review_points=review_points, comment_points=comment_points)
def view_particular_list(ulid): viewer_id = flask.session['user_id'] with easypg.cursor() as cur: login = user.get_user_login(cur, viewer_id) list_owner_id = lists.get_owner_for_list(cur, ulid) list_owner_login = user.get_user_login(cur, list_owner_id) list_info = lists.get_books_in_list(cur, ulid) num_books_in_list = list_info.__len__() list_name = lists.get_list_name(cur, ulid) comment_info = comments.get_comments_for_list(cur, ulid) if login == list_owner_login: same_user = True else: same_user = False return flask.render_template('list.html', login=login, list_owner_login=list_owner_login, list_owner_id=list_owner_id, num_books_in_list=num_books_in_list, list_info=list_info, list_name=list_name, same_user=same_user, ulid=ulid, comment_info=comment_info)
def unfollow_from_user_page(uid): f = request.form for key in f.keys(): remove_follower = f.getlist(key)[0] with easypg.cursor() as cur: follows.unfollow(cur, session['username'], remove_follower) return redirect('/users/' + uid)
def get_frnd_actvty(uid): with easypg.cursor() as cur: user_id = queries.get_user_id(cur, uid) activity_info = activity.get_friend_activity(cur, user_id) return render_template('activity_list.html', activity_info=activity_info, uid=uid)
def account_details(): uid = flask.session['user_id'] with easypg.cursor() as cur: user_info = user.get_user_info(cur, uid) user_list = lists.get_user_list_info(cur, uid) num_lists = lists.get_num_lists_for_user(cur, uid) books_read = books.get_books_read(cur, uid) num_books_read = books.num_books_read(cur, uid) friends_list = friends.get_all_friends(cur, uid) total_pages_read = books.num_pages_read(cur, uid) num_friends_targeting_user = friends.num_friends_targeting_user(cur, uid) num_friends = friends.num_friends_for_user(cur, uid) friends_targeting = friends.get_friends_targeting_user(cur, uid) return flask.render_template('account.html', books_read=books_read, num_books_read=num_books_read, num_lists=num_lists, user_info=user_info, #user_list=user_list, list_name=user_list, friends=friends_list, num_friends=num_friends, friends_for_user=num_friends_targeting_user, friends_targeting=friends_targeting, total_pages_read=total_pages_read)
def unlk_review(uid, review_id): with easypg.cursor() as cur: f = request.form for key in f.keys(): unlike_review = f.getlist(key)[0] reviews.unlike_review(cur, review_id, session['user_id']) return redirect('/reviews/' + uid + '/' + review_id)
def register_index(): errors = [] if flask.request.method == 'POST': if flask.request.form['password'] != flask.request.form['password_confirm']: errors.append("Passwords do not match!") elif not re.match(r"[^@]+@[^@]+\.[^@]+", flask.request.form['email']): # KISS here, just confirm one @ sign, period after @ sign; no confirmation address is active # from: http://stackoverflow.com/a/8022584/1431509 errors.append("Email address not valid!") else: with easypg.cursor() as cur: register_status, id, message = users.register_user(cur, flask.request.form) if register_status: user = User.get(id) try: if flask.request.form['remeberLogin'] == "remeber-me": remember = True except KeyError: remember = False flask.ext.login.login_user(user, remember) flask.flash("Registered and Logged in successfully.") flask.flash("Good to meet you %s!" % flask.request.form['username']) else: errors.append(message) return flask.render_template("register.html", errors=errors)
def compare_unpw(username, pw_challenge): """ Compares the password given to the hashed version in the database :param username: The username for which to authenticate against. :param pw_challenge: The password to challenge authentication. :return: """ with easypg.cursor() as cur: cur.execute( ''' SELECT password FROM users WHERE username = %s ''', (username, )) # See this page for more information http://www.tutorialspoint.com/python/python_tuples.htm user_info = cur.fetchone() if user_info is None: return False else: #for row in user_info: # print row pw = user_info[0] if bcrypt.hashpw(pw_challenge, pw) == pw: return True else: return False
def register_index(): errors = [] if flask.request.method == "POST": if flask.request.form["password"] != flask.request.form["password_confirm"]: errors.append("Passwords do not match!") elif not re.match(r"[^@]+@[^@]+\.[^@]+", flask.request.form["email"]): # KISS here, just confirm one @ sign, period after @ sign; no confirmation address is active # from: http://stackoverflow.com/a/8022584/1431509 errors.append("Email address not valid!") else: with easypg.cursor() as cur: register_status, id, message = users.register_user(cur, flask.request.form) if register_status: user = BooknetUser.get(id) try: if flask.request.form["remeberLogin"] == "remeber-me": remember = True except KeyError: remember = False flask.ext.login.login_user(user, remember) flask.flash("Registered and Logged in successfully.") flask.flash("Good to meet you %s!" % flask.request.form["username"]) return flask.redirect(flask.url_for("home_index")) else: errors.append(message) if "next" in flask.request.args: next = flask.request.args["next"] else: next = None return flask.render_template("register.html", errors=errors, next=next)
def compare_unpw(username, pw_challenge): """ Compares the password given to the hashed version in the database :param username: The username for which to authenticate against. :param pw_challenge: The password to challenge authentication. :return: """ with easypg.cursor() as cur: cur.execute(''' SELECT password FROM users WHERE username = %s ''', (username, )) # See this page for more information http://www.tutorialspoint.com/python/python_tuples.htm user_info = cur.fetchone() if user_info is None: return False else: #for row in user_info: # print row pw = user_info[0] if bcrypt.hashpw(pw_challenge, pw) == pw: return True else: return False
def books_by_authors(): page, sorting, sort_direction = parse_sorting() start, limit = get_item_limits(page) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): total_pages, book_info = books.get_books_by_authors( cur, start, limit, flask.session["user_id"], sorting, sort_direction ) else: total_pages, book_info = books.get_books_by_authors(cur, start, limit, None, sorting, sort_direction) if sorting: parameters = "&sorting=%s&sort_direction=%s" % (sorting, sort_direction) else: parameters = "" sort_options = { "Author Name": "author_name", "Avg. Rating": "avg_rating", "# Pages": "num_pages", "# Books": "num_books", } return render_books_index( "books_by_authors.html", book_info, total_pages, sort_options, parameters, "Books By Authors" )
def display_reviews_for_book(bid): page, sorting, sort_direction = parse_sorting() start, limit = get_item_limits(page) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): current_user_id = flask.ext.login.current_user.id else: current_user_id = None total_pages, review_info = reviews.get_reviews_by_book(cur, start, limit, bid, current_user_id) if page > 1: prevPage = page - 1 else: prevPage = None if page == total_pages: nextPage = None else: nextPage = page + 1 return flask.render_template( "review_list.html", reviews=review_info["reviews"], page_title="Reviews for: %s" % review_info["book_info"]["title"], page=page, totalPages=total_pages, nextPage=nextPage, prevPage=prevPage, )
def books_by_authors(): page, sorting, sort_direction = parse_sorting() start, limit = get_item_limits(page) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): total_pages, book_info = books.get_books_by_authors( cur, start, limit, flask.session['user_id'], sorting, sort_direction) else: total_pages, book_info = books.get_books_by_authors( cur, start, limit, None, sorting, sort_direction) if sorting: parameters = "&sorting=%s&sort_direction=%s" % (sorting, sort_direction) else: parameters = '' sort_options = { "Author Name": "author_name", "Avg. Rating": "avg_rating", "# Pages": "num_pages", "# Books": "num_books" } return render_books_index('books_by_authors.html', book_info, total_pages, sort_options, parameters, 'Books By Authors')
def add_book_handler(): title = flask.request.form['title'] edition = flask.request.form['edition'] isbn = flask.request.form['isbn'] author_name = flask.request.form['author_name'] publisher = flask.request.form['publisher'] pub_date = flask.request.form['pub_date'] pages = flask.request.form['pages'] cover_type = flask.request.form['cover_type'] description = flask.request.form['description'] if title == "": flask.abort(402) if edition == "": flask.abort(402) if isbn == "": flask.abort(402) if author_name == "": flask.abort(402) if publisher == "": flask.abort(402) if pages == "": flask.abort(402) with easypg.cursor() as cur: aid = books.get_author_id(cur, author_name) bid = editBook.add_book(cur, title, edition, isbn, author_name, publisher, pub_date, pages, cover_type, description, aid) bid = str(bid) return flask.redirect('/books/' + bid)
def add_book_list(): errors = [] app.logger.info('Received new data for list from user_id %s: %s', flask.ext.login.current_user.id, flask.request.form) with easypg.cursor() as cur: entry_status, messages, list_id = lists.add_book_to_list( cur, flask.ext.login.current_user.id, flask.request.form) app.logger.info("Review submitted %s - %s - %s", entry_status, messages, list_id) if entry_status: for message in messages: flask.flash(message) return flask.redirect( flask.request.args.get("next") or flask.url_for("display_list", lid=list_id)) else: for message in messages: errors.append(message) if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("reviews_index") return flask.redirect(next)
def reviews_index(): page, sorting, sort_direction = parse_sorting() start, limit = get_item_limits(page) with easypg.cursor() as cur: total_pages, review_info = reviews.get_review_range(cur, start, limit) if page > 1: prevPage = page - 1 else: prevPage = None if page == total_pages: nextPage = None else: nextPage = page + 1 return flask.render_template( "review_list.html", reviews=review_info, page_title="Reviews", page=page, totalPages=total_pages, nextPage=nextPage, prevPage=prevPage, )
def login_index(): # Login page errors = [] if flask.request.method == "POST": # login and validate the user... with easypg.cursor() as cur: login_status = users.validate_login(cur, flask.request.form) if login_status > 0: user = BooknetUser.get(login_status) try: if flask.request.form["remeberLogin"] == "remeber-me": remember = True except KeyError: remember = False print user.is_active flask.ext.login.login_user(user, remember) flask.flash("Logged in successfully.") return flask.redirect(flask.request.args.get("next") or flask.url_for("home_index")) else: errors.append("Username or password not accepted.") if "next" in flask.request.args: next = flask.request.args["next"] else: next = None return flask.render_template("login.html", errors=errors, next=next)
def add_book(bid): errors = [] if flask.request.method == 'POST': with easypg.cursor() as cur: edit_status, messages, book_id = books.add_book( cur, bid, flask.ext.login.current_user.id, flask.request.form) print "Posted book data: %s..." % messages if edit_status: for message in messages: flask.flash(message) return flask.redirect( flask.request.args.get("next") or flask.url_for("display_book", bid=book_id)) else: for message in messages: errors.append(message) if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("home_index") book_info = {'title': 'New Book Addition', 'core_id': '0'} return flask.render_template("book_edit_form.html", book_info=book_info, page_title="Add A Book!", error=errors, next=next)
def display_reviews_for_book(bid): page, sorting, sort_direction = parse_sorting() start, limit = get_item_limits(page) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): current_user_id = flask.ext.login.current_user.id else: current_user_id = None total_pages, review_info = reviews.get_reviews_by_book( cur, start, limit, bid, current_user_id) if page > 1: prevPage = page - 1 else: prevPage = None if page == total_pages: nextPage = None else: nextPage = page + 1 return flask.render_template('review_list.html', reviews=review_info['reviews'], page_title='Reviews for: %s' % review_info['book_info']['title'], page=page, totalPages=total_pages, nextPage=nextPage, prevPage=prevPage)
def add_book_list(): errors = [] app.logger.info( "Received new data for list from user_id %s: %s", flask.ext.login.current_user.id, flask.request.form ) with easypg.cursor() as cur: entry_status, messages, list_id = lists.add_book_to_list( cur, flask.ext.login.current_user.id, flask.request.form ) app.logger.info("Review submitted %s - %s - %s", entry_status, messages, list_id) if entry_status: for message in messages: flask.flash(message) return flask.redirect(flask.request.args.get("next") or flask.url_for("display_list", lid=list_id)) else: for message in messages: errors.append(message) if "next" in flask.request.args: next = flask.request.args["next"] else: next = flask.url_for("reviews_index") return flask.redirect(next)
def user_page(uid): with easypg.cursor() as cur: following = follows.get_follow_status(cur, session['username'], uid) return render_template('user_main_page.html', uid = uid, following = following )
def print_followers(uid): if 'page' in request.args: page = int(request.args['page']) else: page = 1 if page <= 0: abort(404) id = session['username'] with easypg.cursor() as cur: followers = follows.get_followers(cur, page, id) total_pages = follows.get_follower_pg_cnt(cur, id) return render_template('followers.html', follow = followers, page = page, total_pages = total_pages, user = id ) if page > 1: prevPage = page - 1 else: prevPage = None if page < total_pages: nextPage = page + 1 else: nextPage = None
def print_followees(user_id): if request.method == "GET": if 'page' in request.args: page = int(request.args['page']) else: page = 1 if page <= 0: abort(404) with easypg.cursor() as cur: followees = follows.get_followees(cur, page, user_id) total_pages = follows.get_followee_pg_cnt(cur, user_id) return render_template('followees.html', follow = followees, page = page, total_pages = total_pages, uid = user_id ) if page > 1: prevPage = page - 1 else: prevPage = None if page < total_pages: nextPage = page + 1 else: nextPage = None
def login_index(): # Login page errors = [] if flask.request.method == 'POST': # login and validate the user... with easypg.cursor() as cur: login_status = users.validate_login(cur, flask.request.form) if login_status > 0: user = BooknetUser.get(login_status) try: if flask.request.form['remeberLogin'] == "remeber-me": remember = True except KeyError: remember = False print user.is_active flask.ext.login.login_user(user, remember) flask.flash("Logged in successfully.") return flask.redirect( flask.request.args.get("next") or flask.url_for("home_index")) else: errors.append("Username or password not accepted.") if 'next' in flask.request.args: next = flask.request.args['next'] else: next = None return flask.render_template("login.html", errors=errors, next=next)
def display_books_with_covers(): page, sorting, sort_direction = parse_sorting() start, limit = get_item_limits(page) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): total_pages, publisher_info = books.get_books_with_covers( cur, start, limit, flask.session['user_id'], sorting, sort_direction) else: total_pages, publisher_info = books.get_books_with_covers( cur, start, limit, None, sorting, sort_direction) sort_options = { "Title": "book_title", "Publication Date": "publication_date", "Avg. Rating": "avg_rating", "Number of Readers": "num_readers" } if sorting: parameters = "&sorting=%s&sort_direction=%s" % (sorting, sort_direction) else: parameters = '' return render_books_index('books_index.html', publisher_info, total_pages, sort_options, parameters, 'Books With Covers')
def display_publisher(pid): page, sorting, sort_direction = parse_sorting() start, limit = get_item_limits(page) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): total_pages, publisher_info = books.get_books_by_publisher( cur, start, limit, pid, flask.session["user_id"], sorting, sort_direction ) else: total_pages, publisher_info = books.get_books_by_publisher( cur, start, limit, pid, None, sorting, sort_direction ) sort_options = { "Title": "book_title", "Publication Date": "publication_date", "Avg. Rating": "avg_rating", "Number of Readers": "num_readers", } if sorting: parameters = "&sorting=%s&sort_direction=%s" % (sorting, sort_direction) else: parameters = "" return render_books_index( "author.html", publisher_info, total_pages, sort_options, parameters, "Books - %s" % publisher_info["name"] )
def user_dashboard_following(): with easypg.cursor() as cur: user_info = users.get_user_feed(cur, flask.ext.login.current_user.get_id()) # user_info['name'] = flask.ext.login.current_user.name return flask.render_template('dashboard_following.html', user_info=user_info)
def add_book(bid): errors = [] if flask.request.method == "POST": with easypg.cursor() as cur: edit_status, messages, book_id = books.add_book( cur, bid, flask.ext.login.current_user.id, flask.request.form ) print "Posted book data: %s..." % messages if edit_status: for message in messages: flask.flash(message) return flask.redirect(flask.request.args.get("next") or flask.url_for("display_book", bid=book_id)) else: for message in messages: errors.append(message) if "next" in flask.request.args: next = flask.request.args["next"] else: next = flask.url_for("home_index") book_info = {"title": "New Book Addition", "core_id": "0"} return flask.render_template( "book_edit_form.html", book_info=book_info, page_title="Add A Book!", error=errors, next=next )
def get_frnd_actvty(uid): with easypg.cursor() as cur: user_id = queries.get_user_id(cur, uid) activity_info = activity.get_friend_activity(cur, user_id) return render_template('activity_list.html', activity_info = activity_info, uid = uid)
def display_review(rid): with easypg.cursor() as cur: review_info = reviews.get_review(cur, rid) if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("reviews_index") return flask.render_template("review.html", review=review_info, next=next)
def display_log(lid): with easypg.cursor() as cur: log_info = logs.get_log(cur, lid) if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("home_index") return flask.render_template("log.html", log=log_info, next=next)
def unfollow_from_frinds_list(user_id): f = request.form for key in f.keys(): remove_follower = f.getlist(key)[0] if request.method == "POST": with easypg.cursor() as cur: #remove_follower = request.form['unfollow'] follows.unfollow(cur, session['username'], remove_follower) return redirect('/follows/' + user_id)
def home_index(): with easypg.cursor() as cur: pages, book_info = books.get_spotlight_books(cur, 4) pages, review_info = reviews.get_spotlight_reviews(cur, 4) list_info = lists.get_spotlight_lists(cur, 4) return flask.render_template('home.html', books=book_info, reviews=review_info, lists=list_info)
def get_author(aid): with easypg.cursor() as cur: info = authors.get_author(cur, aid) if info is None: flask.abort(404) return flask.render_template('authors.html', author_id=aid, **info)
def get_title(tid): if request.method == 'GET': with easypg.cursor() as cur: title_info = books.get_title(cur, tid) if title_info is None: abort(404) return render_template('book.html', edition_id=tid, **title_info) if request.method == 'POST': with easypg.cursor() as cur: print "Working!!!" #rating = request.form['rating'] review = request.form['review'] #user_lists.add_rating(cur, session['user_id'],tid, rating) user_lists.add_review(cur, session['user_id'], tid, review, 0) print "done!" return redirect('/books/' + tid)
def get_review(uid, rid): with easypg.cursor() as cur: review_info = reviews.get_user_review(cur, rid) author_list = reviews.get_author_names(cur, rid) num_likes = reviews.get_likes(cur, rid, session['user_id']) return render_template('review_text.html', uid=uid, author_list=author_list, num_likes=num_likes, **review_info)
def users_index(): if 'sorting' in flask.request.args: sorting = flask.request.args['sorting'] else: sorting = None if 'sort_direction' in flask.request.args: sort_direction = flask.request.args['sort_direction'] else: sort_direction = None if 'page' in flask.request.args: page = int(flask.request.args['page']) else: page = 1 if page <= 0: flask.abort(404) with easypg.cursor() as cur: total_pages = users.get_total_pages(cur) with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): user_info = users.get_all_users(cur, page, flask.session['user_id']) else: user_info = users.get_all_users(cur, page) if page > 1: prevPage = page - 1 else: prevPage = None if page == total_pages: nextPage = None else: nextPage = page + 1 return flask.render_template('users.html', users=user_info, page=page, totalPages=total_pages, nextPage=nextPage, prevPage=prevPage)
def user_dashboard(): if flask.ext.login.current_user.is_authenticated(): current_user_id = flask.session['user_id'] else: current_user_id = None with easypg.cursor() as cur: user_info = users.get_user(cur, current_user_id, current_user_id) # print user_info return flask.render_template('dashboard_overview.html', user_info=user_info)
def edit_list(uid, list_id): if request.method == "GET": with easypg.cursor() as cur: list_books = user_lists.get_books_in_list(cur, list_id) #if list_books is None: # abort(404) return render_template('edit_list.html', uid=uid, l_id=list_id, list_books=list_books)
def display_book(bid): with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): book_info = books.get_book(cur, bid, flask.ext.login.current_user.id) else: book_info = books.get_book(cur, bid) # print book_info if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("home_index") return flask.render_template("book.html", book_info=book_info, next=next)
def display_list(lid): with easypg.cursor() as cur: if flask.ext.login.current_user.is_authenticated(): list_info = lists.get_list(cur, lid, flask.ext.login.current_user.id) else: list_info = lists.get_list(cur, lid) if 'next' in flask.request.args: next = flask.request.args['next'] else: next = flask.url_for("home_index") return flask.render_template("list.html", list=list_info, next=next)