コード例 #1
0
ファイル: routes.py プロジェクト: devops-cohort/Shaybs
def edit_review(id):

    add_review = False

    review = Reviews.query.get_or_404(id)
    form = ReviewForm(obj=review)
    if form.validate_on_submit():
        review.review_author = form.review_author.data
        review.review = form.review.data
        review.rating = form.rating.data
        book_ref = form.book.data
        db.session.commit()
        flash('You have successfully edited the review')
        #return to books list
        return redirect(url_for('reviews'))

    form.book.data = review.book_ref
    form.rating.data = review.rating
    form.review.data = review.review
    form.review_author.data = review.review_author

    return render_template('review.html',
                           action="Edit",
                           add_review=add_review,
                           review=review,
                           form=form,
                           title="Edit Review")
コード例 #2
0
def add_review(idnum):
    form = ReviewForm()
    if form.validate_on_submit():
        new_review = Review(rev=form.rev.data, rating=form.rating.data, movies_id=idnum)
        db.session.add(new_review)
        db.session.commit()
        return redirect(url_for('reviews', idnum=idnum))
    return render_template('add_review.html', form=form, movies= Movies.query.get(idnum))
コード例 #3
0
def addReview(idNum):
    form = ReviewForm()
    if form.validate_on_submit():
        new_review = Review(desc=form.desc.data,
			rating=form.rating.data,
			series_id=idNum)
        db.session.add(new_review)
        db.session.commit()
        return redirect(url_for('Reviewpage', idNum=idNum))
    return render_template('addReview.html', form=form, series = Series.query.get(idNum))
コード例 #4
0
def add():
    form = ReviewForm()
    all_games = Games.query.all()
    game_choices = []
    for game in all_games:
        game_choices.append((str(game.id), game.game))
    form.gameid.choices = game_choices
    if form.validate_on_submit():
        new_review = Review(review=form.review.data, game_id=form.gameid.data)
        db.session.add(new_review)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
コード例 #5
0
def add():
    form = ReviewForm()
    all_players = Players.query.all()
    player_choices = []
    for player in all_players:
        player_choices.append((str(player.id), player.player))
    form.playerid.choices = player_choices
    if form.validate_on_submit():
        new_review = Review(review=form.review.data,
                            players_id=form.playerid.data)
        db.session.add(new_review)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
コード例 #6
0
ファイル: routes.py プロジェクト: Alex-Bane/crud-project
def update(review_id):
    form = ReviewForm()
    albums = Albums.query.all()
    album_choices = []
    for album in albums:
        album_choices.append((str(album.id), album.album))
    form.albumid.choices = album_choices
    review_to_update = Review.query.get(review_id)
    if form.validate_on_submit():
        review_to_update.review = form.review.data
        db.session.commit()
        return redirect(url_for('index'))
    elif request.method == 'GET':
        form.review.data = review_to_update.review
    return render_template('update.html', form=form)
コード例 #7
0
def update(review_id):
    form = ReviewForm()
    all_games = Games.query.all()
    game_choices = []
    for game in all_games:
        game_choices.append((str(game.id), game.game))
    form.gameid.choices = game_choices
    review_to_update = Review.query.get(review_id)
    if form.validate_on_submit():
        review_to_update.review = form.review.data
        db.session.commit()
        return redirect(url_for('index'))
    elif request.method == 'GET':
        form.review.data = review_to_update.review
    return render_template('update.html', form=form)
コード例 #8
0
def update(review_id):
    form = ReviewForm()
    all_players = Players.query.all()
    player_choices = []
    for player in all_players:
        player_choices.append((str(player.id), player.player))
    form.playerid.choices = player_choices
    review_to_update = Review.query.get(review_id)
    if form.validate_on_submit():
        review_to_update.review = form.review.data
        db.session.commit()
        return redirect(url_for('index'))
    elif request.method == 'GET':
        form.review.data = review_to_update.review
    return render_template('update.html', form=form)
コード例 #9
0
ファイル: routes.py プロジェクト: Alex-Bane/crud-project
def add():
    form = ReviewForm()
    albums = Albums.query.all()
    album_choices = []
    for album in albums:
        album_choices.append((str(album.id), album.album))
    form.albumid.choices = album_choices
    if form.validate_on_submit():
        new_review = Review(review=form.review.data,
                            album_id=form.albumid.data,
                            rating=form.rating.data)
        db.session.add(new_review)
        db.session.commit()
        return redirect(url_for('index'))
    return render_template('add.html', form=form)
コード例 #10
0
def review(car_id):
    form = ReviewForm()
    car = Cars.query.filter_by(car_id=car_id).first()
    if request.method == "POST":
        if form.validate_on_submit():
            new_review = Reviews(name=form.name.data,
                                 review=form.review.data,
                                 raiting=form.raiting.data,
                                 car_id=car_id)
            db.session.add(new_review)
            db.session.commit()
            return redirect(url_for("home"))
    return render_template("review.html",
                           form=form,
                           title="Add a Review",
                           review=review)
コード例 #11
0
def create():
    form = ReviewForm()
    if request.method == "POST":
        if form.validate_on_submit():

            game_name = form.recommendations.data.name
            game = Games.query.filter_by(name=game_name).first()
            new_review = Reviews(author=form.author.data,
                                 body=form.body.data,
                                 rating=form.rating.data,
                                 game=game.id)
            db.session.add(new_review)
            db.session.commit()
            return redirect(url_for("home"))

    return render_template('add.html', title="Create a task", form=form)
コード例 #12
0
def review():
    form = ReviewForm()
    reviews = Reviews.query.all()
    if form.validate_on_submit():
        reviewData = Reviews(title=form.title.data,
                             content=form.content.data,
                             author=current_user)
        db.session.add(reviewData)
        db.session.commit()
        return redirect(url_for('review'))
    else:
        print(form.errors)
    return render_template('review.html',
                           title='Review',
                           form=form,
                           reviews=reviews)
コード例 #13
0
def review():
    form = ReviewForm()
    if form.validate_on_submit():
        game = Games.query.filter_by(game_title=form.game_title.data).first()
        reviewData = Reviews(game_id=game.id,
                             first_name=form.first_name.data,
                             last_name=form.last_name.data,
                             rating=form.rating.data,
                             title=form.title.data,
                             review=form.review.data)
        db.session.add(reviewData)
        db.session.commit()

        return redirect(url_for('home'))
    else:
        print(form.errors)

    return render_template('reviews.html', title="Game Reviews", form=form)
コード例 #14
0
def update_review(review_id):
    review = Reviews.query.get_or_404(review_id)
    form = ReviewForm()
    if form.validate_on_submit():
        review.first_name = form.first_name.data
        review.last_name = form.last_name.data
        review.rating = form.rating.data
        review.title = form.title.data
        review.review = form.review.data

        db.session.commit()
        return redirect(url_for('reviews', review_id=review.id))
    elif request.method == 'GET':
        form.first_name.data = review.first_name
        form.last_name.data = review.last_name
        form.rating.data = review.rating
        form.title.data = review.title
        form.review.data = review.review

    return render_template('reviews.html', title='Update Review', form=form)
コード例 #15
0
def update(id):
    form = ReviewForm()
    review = Reviews.query.filter_by(id=id).first()
    if request.method == "POST":
        review.body = form.body.data
        review.rating = form.rating.data
        db.session.commit()
        return redirect(url_for("home"))
    return render_template("update.html",
                           form=form,
                           title="Update Review",
                           review=review)
コード例 #16
0
def book(id):
    book = db.session.execute("SELECT * FROM books WHERE id = :id",
    {"id":id}).fetchone()
    form = ReviewForm()

    form.set_id(id)

    if form.validate_on_submit():
        db.session.execute("INSERT INTO reviews(user_id, book_id, rating, comment) VALUES (:user_id, :book_id, :rating, :comment)",
        {"user_id":current_user.get_id(), "book_id":id, "rating":form.rating.data, "comment":form.comment.data})
        db.session.commit()

    goodreads = requests.get("https://www.goodreads.com/book/review_counts.json", params={"key": "5eOT5bKjx84fcqynncVpg", "isbns": book.isbn})



    reviews = db.session.execute("SELECT * FROM reviews JOIN users ON reviews.user_id = users.id WHERE book_id = :book_id", {"book_id":id})

    if goodreads.status_code == 200:
        return render_template('book.html', id = id, book = book, form = form, reviews = reviews.fetchall(), goodreads = goodreads.json()['books'][0]['average_rating'])
    else:
        return render_template('book.html', id = id, book = book, form = form, reviews = reviews.fetchall())
コード例 #17
0
ファイル: routes.py プロジェクト: devops-cohort/Shaybs
def add_review():

    add_review = True

    form = ReviewForm()
    if form.validate_on_submit():
        review = Reviews(review_author=form.review_author.data,
                         review=form.review.data,
                         rating=form.rating.data,
                         book_ref=form.book.data)
        try:
            db.session.add(review)
            db.session.commit()
            flash('You have successfully added a new Review')
        except:
            flash('Error: The review already exists')
        return redirect(url_for('reviews'))

    return render_template('review.html',
                           action="Add",
                           title='Add Review',
                           form=form,
                           add_review=add_review)
コード例 #18
0
def book(isbn):
    form = ReviewForm()
    message = None
    error = False
    is_reviewed = False
    fallback = "https://images.unsplash.com/photo-1499482125586-91609c0b5fd4?ixid=MXwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=634&q=80"

    if request.method == 'POST' and session['logged_in']:
        my_rating = int(request.form.get('rating'))
        my_review = request.form.get('review')
        book_id = request.form.get('book_id')

        if my_review.strip() == "" or my_rating == "":
            message = "Invalid Review"
        else:
            db.execute(
                "INSERT INTO review (username, review, rating, book_id) select :username,:review,:rating,:book_id where not exists (select * from review where username = :username and book_id = :book_id);",
                {
                    'username': session['username'],
                    'review': my_review,
                    'rating': my_rating,
                    'book_id': book_id
                })
            db.commit()
            is_reviewed = True
    res = db.execute("select * from books where isbn=:isbn;", {
        'isbn': isbn
    }).fetchone()
    if res == None:
        return render_template('book.html')

    reviews = db.execute("select * from review where book_id=:id;", {
        'id': res.id
    }).fetchall()
    if request.method == "GET":
        try:
            if session['logged_in']:
                check_review = db.execute(
                    "select username from review where book_id=:id and username=:username;",
                    {
                        'id': res.id,
                        'username': session['username']
                    }).fetchone()
                if check_review != None:
                    is_reviewed = True
        except:
            pass
    try:
        pageNum, rating, description, image_link, ratingsCount = get_google_books_data(
            isbn)
    except:
        error = True
        pageNum, rating, description, image_link, ratingsCount = 0, 0, "", fallback, 0

    return render_template('book.html',
                           obj_book=res,
                           form=form,
                           pageNum=pageNum,
                           description=description,
                           image_link=image_link,
                           rating=rating,
                           ratingsCount=ratingsCount,
                           reviews=reviews,
                           message=message,
                           is_reviewed=is_reviewed,
                           error=error)