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): 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_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_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(): 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_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_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))
def reviews_form(): book_id = request.args.get("book_id") book = Book.query.get(book_id) form = ReviewForm() form.book_id.data = book_id return render_template("reviews/new.html", form=form, book=book)
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 updating_review_view(review_id): review = Review.query.get(review_id) form = ReviewForm(request.form) form.rating.data = review.rating form.reviewText.data = review.review_text return render_template("reviews/update.html", review_id=review_id, form=form)
def reviews_form(game_id): game = Game.query.get(game_id) if not game: return redirect(url_for('games_index')) if already_reviewed(current_user, game.reviews): return redirect(url_for('reviews_show', game_id = game.id)) return render_template('reviews/new.html', game = game, form = ReviewForm() )
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_editform(review_id): form = ReviewForm() review = Review.query.get(review_id) game = Game.query.get(review.game_id) if not (review and game): return redirect(url_for('games_index')) return render_template('reviews/edit.html', review = review, form = form, game = game )
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 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))
def recipe_view(recipe_id): recipe = Recipe.query.get(recipe_id) if not recipe: return redirect(url_for("recipes_index")) review = None if current_user.is_authenticated: review = Review.query.filter_by(account_id=current_user.id, recipe_id=recipe_id).first() form = ReviewForm() if review: form.rating.data = review.rating rating = Recipe.get_average_rating(recipe_id) return render_template("recipes/view.html", recipe=recipe, form=form, rating=rating, review_exists=review is not None)
def reviews_form(): return render_template("reviews/new.html", form=ReviewForm())
def reviews_form(): return render_template("reviews/new.html", form=ReviewForm(), readonly=False)
def reviews_form(movie_id): return render_template("reviews/new.html", form = ReviewForm(), movie = Movie.query.get(movie_id))
def reviews_form(game_id): form = ReviewForm() form.game_id.data = game_id return render_template("reviews/new.html", form = form, game = Game.query.filter_by(id=game_id).first())