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_modify(review_id): re = Review.get_review_by_id(review_id) if re['account_id'] != current_user.id: return login_manager.unauthorized() if request.method == "GET": form = ReviewForm(stars=re['stars']) form.author.data = re['author'] form.name.data = re['book'] form.review.data = re['review'] return render_template("reviews/modify.html", form=form, review_id=review_id) form = ReviewForm(request.form) if not form.validate(): return render_template("reviews/modify.html", form=form) r = Review.query.get(review_id) r.review = form.review.data r.stars = form.stars.data db.session().commit() return redirect(url_for("reviews_index"))
def reviews_modify(review_id): r = Review.query.get(review_id) if not r: return render_template("error.html", error="Arvostelua ei löydy tietokannasta") if not current_user.is_allowed_to_edit_review(r): return render_template("error.html", error="Sinulla ei ole muokkaamisoikeutta") form = ReviewForm(request.form) if request.method == "GET": form.text.data = r.text form.points.data = r.points return render_template("reviews/modify.html", form=form, game=Game.query.get(r.game_id), review_id=review_id) if not form.validate(): return render_template("reviews/modify.html", form=form, game=Game.query.get(r.game_id), review_id=review_id) r.text = form.text.data r.points = form.points.data db.session.commit() return redirect(url_for("games_view", game_id=r.game_id))
def reviews_create(): form = ReviewForm(request.form) if not form.validate(): return render_template("reviews/new.html", form=form) t = Review(form.score.data, form.comment.data) t.account_id = current_user.id db.session().add(t) db.session().commit() return redirect(url_for("reviews_index"))
def reviews_create(movie_id): form = ReviewForm(request.form) if not form.validate(): return render_template("reviews/new.html", form = form, movie = Movie.query.get(movie_id)) r = Review(form.reviewtext.data, form.rating.data) r.account_id = current_user.id r.movie_id = movie_id db.session().add(r) db.session().commit() return redirect(url_for("reviews_for_movie", movie_id = movie_id))
def reviews_create(): form = ReviewForm(request.form) if not form.validate(): book = Book.query.get(form.book_id.data) return render_template("reviews/new.html", form=form, book=book) newReview = Review(form.rating.data, form.reviewText.data, form.book_id.data, current_user.id) db.session().add(newReview) db.session().commit() return redirect(url_for("book_view", book_id=form.book_id.data))
def reviews_edit(id): newReviewData = ReviewForm(request.form) oldReview = Review.query.get(id) if (not newReviewData) or (not oldReview): return redirect(url_for('games_index')) if not newReviewData.validate(): game = Game.query.get(oldReview.game_id) return render_template('reviews/edit.html', review = oldReview, form = newReviewData, game = game ) compareReviewsAndUpdate(oldReview, newReviewData) db.session().commit() return redirect(url_for('reviews_show', game_id = oldReview.game_id))
def review_create(recipe_id): form = ReviewForm(request.form) if not form.validate(): return redirect(url_for("recipe_view", recipe_id=recipe_id)) review = Review.query.filter_by(account_id=current_user.id, recipe_id=recipe_id).first() if not review: review = Review(form.rating.data) review.recipe_id = recipe_id review.account_id = current_user.id db.session().add(review) db.session().commit() else: review.rating = form.rating.data db.session().commit() return redirect(url_for("recipe_view", recipe_id=recipe_id))
def reviews_create(): form = ReviewForm(request.form) given_author = form.author.data given_book = form.name.data if not form.validate(): return render_template("reviews/new.html", form=form) if db.session.query(Author).filter( Author.name == given_author).scalar() is None: a = Author(given_author) db.session.add(a) db.session.commit() if db.session.query(Book).filter( Book.book_name == given_book).scalar() is None: a = db.session.query( Author.id).filter(Author.name == given_author).scalar() b = Book(given_book, a) db.session.add(b) db.session.commit() b = db.session.query(Book.id).filter(Book.book_name == given_book).scalar() r = Review(b, form.review.data, form.stars.data) r.account_id = current_user.id db.session().add(r) if db.session.query(MustReads).filter( MustReads.book_id == b).scalar() is None: mr = MustReads(b) mr.read = True mr.account_id = current_user.id db.session().add(mr) db.session().commit() return redirect(url_for("reviews_index"))
def review_update(review_id): review_for_updating = Review.query.get(review_id) user = current_user book_id = review_for_updating.book_id form = ReviewForm(request.form) updated_review_rating = form.rating.data updated_review_text = form.reviewText.data if not form.validate(): return render_template("reviews/update.html", review_id=review_id, form=form) if review_for_updating.account_id != user.id: return redirect(url_for("updating_review_view", review_id=review_id)) review_for_updating.rating = updated_review_rating review_for_updating.review_text = updated_review_text db.session.commit() return redirect(url_for("book_view", book_id=book_id))
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))