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))
def reviews_create(game_id): game = Game.query.get(game_id) if not game: return redirect(url_for('games_index')) form = ReviewForm(request.form) if not form.validate(): return render_template('reviews/new.html', game = game, form = form ) review = Review( form.content.data, form.rating.data ) review.game_id = game_id review.account_id = current_user.id db.session().add(review) db.session().commit() return redirect(url_for('reviews_show', game_id = game_id))
def reviews_create(game_id): form = ReviewForm(request.form) game = Game.query.get(game_id) if not game: return render_template("error.html", error="PeliƤ ei ole olemassa") if request.method == "GET": return render_template("reviews/new.html", form=ReviewForm(), game=Game.query.get(game_id)) if not form.validate(): return render_template("reviews/new.html", form=form, game=game) if current_user.has_reviewed(game): return render_template("error.html", error="Et voi arvioida samaa peliƤ uudelleen") review = Review(form.text.data, form.points.data) review.game_id = game_id review.account_id = current_user.id db.session().add(review) db.session().commit() return redirect(url_for("games_view", game_id=game_id))