Пример #1
0
def reviews_createOrUpdate():
    if('create' in request.form):
        form = ReviewForm(request.form)

        if not form.validate():
            return render_template("reviews/new.html", form = form, game = Game.query.filter_by(id=form.game_id.data).first())
        game_id = form.game_id.data
        grade = form.grade.data
        text = form.text.data
        
        review = Review(game_id, grade, text)
        review.game_id = game_id
        review.user_id = current_user.id
        
        db.session().add(review)
        db.session().commit()
    elif('edit' in request.form):
        form = ReviewEditForm(request.form)

        if not form.validate():
            return render_template("reviews/edit.html", form = form, game = Game.query.filter_by(id=form.game_id.data).first())
        review_id = form.review_id.data
        review = Review.query.filter_by(id=review_id).first()
        
        review.grade = form.grade.data
        review.text = form.text.data
        
        db.session().commit()
        
    return redirect(url_for("reviews_index", game_id = form.game_id.data))
    
    
    
    
Пример #2
0
def reviews_new(book_id):
    if request.method == "GET":
        return render_template("reviews/new.html",
                               form=ReviewForm(),
                               book_id=book_id)

    user_id = current_user.id
    form = ReviewForm(request.form)

    new_review = Review(form.score.data, form.text.data)
    new_review.user_id = user_id
    new_review.book_id = book_id

    db.session().add(new_review)
    db.session().commit()
    return redirect(url_for("books_show", book_id=book_id))