def hall(name): if name not in HALLS: return redirect('/index') form = ReviewForm() if form.validate_on_submit(): #flash('Review="%s", Rating=%s' % #(form.review.data, str(form.rating.data))) r = models.Review(review=form.review.data, score=form.rating.data, location=name) db.session.add(r) db.session.commit() return redirect('/hall/' + name) reviews = models.Review.query.all()[::-1] reviews = filter(lambda review: review.location == name, reviews) if len(reviews) > 0: average_score = sum([review.score for review in reviews]) / (len(reviews) + 0.0) average_score = "%.1f" % average_score else: average_score = 0 return render_template('new_reviews.html', form=form, reviews=reviews, location=name, average_score=average_score, image=HALLS[name], halls=HALLS.keys())
def write(courseid): if courseid < 0: abort(404) course = Course.query.get_or_404(courseid) from datetime import datetime form = reviewSubmissionForm() if form.validate_on_submit(): try: review = models.Review(review_date= datetime.utcnow(), review_comment=form.comment.data, rating =int(form.rating.data), course_id=course.id,\ user_id =g.user.id) db.session.add(review) db.session.commit() flash("Review posted successfully", "success") return redirect('home') except: db.session.rollback() flash( "Sorry you can't post more than one review for a single course. Please edit the former one below.", "error") return redirect( url_for('editreview', courseid=course.id, userid=g.user.id)) return render_template('write.html', form=form, course=course, edit=False, title="Write Review")
def index_products_data(): count = 1 data = [] for product_data in models.scrape_li: review_count = 1 reviews = product_data['reviews'] for review in reviews: r = models.Review() r.reviewid = product_data['url'] + "?review=" + str(review_count) review_count = review_count + 1 r.perfume = product_data['perfume'] r.site = product_data['site'] r.brand_name = product_data['brand_name'] r.brand_variant = product_data['brand_variant'] r.review_date = datetime.strptime(review['date'], '%b %d %Y').date() r.review = review['body'] r.label = review['label'] r.accords = product_data.get('accords', {}) notespyramid = product_data.get('notespyramid', {}) r.notespyramid = notespyramid.get('top', []) r.moods = product_data.get('moods', {}) r.notes = product_data.get('notes', {}) r.longevity = product_data.get('longevity', {}) r.sillage = product_data.get('sillage', {}) r.ratings = product_data.get('ratings', {}) r.img_src = product_data.get('img_src', "") data.append(elastic.convert_for_bulk(r, 'update')) count = count + 1 if count > 100: bulk(models.client, actions=data, stats_only=True) count = 1 bulk(models.client, actions=data, stats_only=True)
def _db_user2_reviews(db_users, db_movies, session): _, user2 = db_users movie1, movie2, _ = db_movies review_movie1 = models.Review( user=user2, movie=movie1, rate=2, datetime=datetime.now() ) review_movie2 = models.Review( user=user2, movie=movie2, rate=4, text='average', datetime=datetime.now() ) session.add(review_movie1) session.add(review_movie2) session.commit() return review_movie1, review_movie2
def _db_user1_reviews(db_users, db_movies, session): user1, _ = db_users movie1, movie2, movie3 = db_movies review_movie1 = models.Review( user=user1, movie=movie1, rate=10, text='very good', datetime=datetime.now() ) review_movie2 = models.Review( user=user1, movie=movie2, rate=2, text='boring', datetime=datetime.now() ) review_movie3 = models.Review( user=user1, movie=movie3, rate=7, datetime=datetime.now() ) session.add(review_movie1) session.add(review_movie2) session.add(review_movie3) session.commit() return review_movie1, review_movie2, review_movie3
def product_put(product_id): product = models.Product.query.get(product_id) review = request.json.get('data') if not product or not review: return jsonify({'mas': 'Bad request'}), 400 new_review = models.Review( asin=product.asin, title=review['title'], review=review['review'], product=product, product_id=product_id ) db.session.add(new_review) db.session.commit() return jsonify({'msg': f'New review for {product.title} created'}), 200
def reviews(): form = ReviewForm() if form.validate_on_submit(): #flash('Review="%s", Rating=%s' % #(form.review.data, str(form.rating.data))) r = models.Review(review=form.review.data, score=form.rating.data, location="TESTPLACE") db.session.add(r) db.session.commit() return redirect('/reviews') return render_template('reviews.html', form=form, halls=HALLS)
def create_review( session: Session, current_user: schemas.User, db_movie: models.Movie, review: schemas.ReviewCreate, ) -> models.Review: db_review = models.Review( **review.dict(), movie_id=db_movie.id, user_id=current_user.id, datetime=datetime.datetime.now(), ) session.add(db_review) session.flush() session.refresh(db_review) update_avg_rating_of_movie(session=session, db_movie=db_movie) return db_review
def push_review_to_index(): count = 1 data = [] for scrape_perfume in models.scrape_li: review_count =1 scrape_reviews = scrape_perfume[1][4] for scrape_review in scrape_reviews: review = models.Review() review.reviewid = scrape_perfume[1][0] + "?review=" + str(review_count) review_count = review_count + 1 review.perfume = scrape_perfume[0] review.review_date = datetime.strptime(scrape_review[0],'%b %d %Y').date() review.review = scrape_review[1] review.label = scrape_review[2] review.accords = scrape_perfume[1][1] review.img_src = scrape_perfume[1][5] if count < 100: data.append(elastic.convert_for_bulk(review, 'update')) count = count + 1 bulk(models.client, actions=data, stats_only=True)