Пример #1
0
def shelve_book_on_gr():
    """ Creates a post request to Goodreads so that the user-selected book can
    be added to their shelves, both within Readerboard and on GR. """

    acct = get_current_account(session['acct'])
    book_id = request.form.get('book')
    shelf = request.form.get('shelf')

    url = 'https://www.goodreads.com/shelf/add_to_shelf.xml'
    params = {'name': shelf, 'book_id': book_id}

    gr_session = OAuth1Session(
        consumer_key=GR_KEY,
        consumer_secret=GR_SECRET,
        access_token=acct.access_token,
        access_token_secret=acct.access_token_secret,
    )

    shelf_request = gr_session.post(url, data=params)

    # TODO: Create a book/edition/shelfbook object and add them to db.
    # book = get_book_details(book_id, GR_KEY)
    # create_books_editions([book], acct.user.gr_id, GR_KEY)

    flash("A book has been added to your " + shelf + " shelf!")
    return render_template("index.html", acct=acct, search=False)
Пример #2
0
def display_challenge_graphs(ch_id):
    """ Returns data about user challenge progress. """

    acct = get_current_account(session['acct'])
    user = acct.User
    challenge_data = get_challenge_data(ch_id, user)

    return jsonify(challenge_data)
Пример #3
0
def get_friends():
    """ Using session data, populates db with user friends. """

    acct = get_current_account(session["acct"])
    get_user_friends(acct, GR_KEY, GR_SECRET)
    search = False

    return render_template("index.html", acct=acct, search=search)
Пример #4
0
def get_shelves(gr_id):
    """ Using account in session, populates db with user's shelves. """

    acct = get_current_account(
        session['acct'])  # send current account for template
    # user = get_user_by_gr_id(gr_id)
    get_all_shelves(gr_id, GR_KEY)
    search = False
    return render_template("index.html", acct=acct, search=search)
Пример #5
0
def search_book():
    """ Processes a user's book search from main search bar and displays results. """

    title = request.form.get("search")
    books = book_search_results(GR_KEY, title)
    acct = get_current_account(session['acct'])
    search = True

    return render_template("index.html", books=books, acct=acct, search=search)
Пример #6
0
def get_books():
    """ Using account in session, populates db with all books from the current
    user's shelves. """

    acct = get_current_account(session['acct'])
    user = get_user_by_acct(acct)
    search = False
    get_all_books_for_user(user, GR_KEY)

    return render_template("index.html", acct=acct, search=search)
Пример #7
0
def landing_page():
    """ Displays user data, or redirects to sign up form. """

    print session

    if 'acct' in session:
        acct = get_current_account(session['acct'])
        search = False
        return render_template("index.html", acct=acct, search=search)

    else:
        return redirect("/signup")
Пример #8
0
def display_chal_info():
    """ Displays user specific info about current challenges, and allows
    a user to create new personal reading challenges. """

    acct = get_current_account(session['acct'])
    user = acct.user

    if request.method == "POST":
        flash("New challenge created!")
        return redirect("/")

    return render_template("challenges.html", user=user, acct=acct)
Пример #9
0
def get_friend_books():
    """ Using the account data from the session, populates db with books for each
    friend in the user's friend list. """

    acct = get_current_account(session['acct'])
    user = get_user_by_acct(acct)
    search = False

    get_all_books_from_friends(user, GR_KEY, GR_SECRET)
    flash("imported all books from your friends!")

    return render_template("index.html", acct=acct, search=search)
Пример #10
0
def view_user_shelf():
    """ Responds to post request from landing page form and renders a list of
    all books on the selected shelf for an authorized user. """

    # FIXME - running into encoding errors with certain shelves - WHY?
    shelf_name = request.form.get('shelf')
    acct = get_current_account(session['acct'])
    user = get_user_by_acct(acct)
    shelf = db.session.query(Shelf).filter(
        Shelf.name == shelf_name, Shelf.user_id == user.user_id).first()
    shelfbooks = shelf.editions

    return render_template("index.html",
                           acct=acct,
                           search=False,
                           shelfbooks=shelfbooks)
Пример #11
0
def display_library_details():
    """ Displays a page for users to select and view details about their home
    library system. """

    acct = get_current_account(session['acct'])
    if request.method == "POST":
        # post request response goes here
        library = request.form.get("library_id")
        session['lib'] = library
        flash("Thanks for selecting your library system!")
        return redirect("/library")

    else:
        if 'lib' in session:
            lib = session['lib']
            library = get_library_details(lib, OVRDRV_KEY, OVRDRV_SECRET)

        else:
            library = None

        return render_template("library_info.html", library=library, acct=acct)
Пример #12
0
def show_book_details(book_id):
    """ Displays details about a book and options to shelve, review, and see
    availability. """

    book = get_book_details(book_id, GR_KEY)
    acct = get_current_account(session["acct"])
    user = get_user_by_acct(acct)
    # query to get all friends of the current user that have read any edition of
    # the currently displayed book.
    friend_matches = db.session.query(Shelf, Edition, ShelfBook, Friendship) \
        .filter(Friendship.user_id == user.user_id) \
        .filter(Shelf.user_id == Friendship.friend_id) \
        .filter(ShelfBook.shelf_id == Shelf.shelf_id) \
        .filter(ShelfBook.ed_id == Edition.ed_id) \
        .filter(Edition.book_id == Book.book_id) \
        .filter(Book.gr_work_id == book['work_id'])\
        .all()

    matches = set(
    )  # create set to prevent duplicate matches (caused by rereading)

    if friend_matches:
        for match in friend_matches:
            user = User.query.get(match.Shelf.user_id)
            matches.add(
                (user.image_url, user.gr_name, match.Shelf.name, user.gr_url))

    matches = list(matches)  # cast matches to a list for iteration in html
    PRODUCT_URL = get_lib_products(WCCLS, OVRDRV_KEY, OVRDRV_SECRET)
    lib_copies = search_lib_for_copies(PRODUCT_URL, book, OVRDRV_KEY,
                                       OVRDRV_SECRET)

    return render_template("book_detail.html",
                           book=book,
                           acct=acct,
                           user=user,
                           matches=matches,
                           lib_copies=lib_copies)