def test_calc_avg_star_rating(self): rating1 = Rating(rating_id=1, stars=4, comments="abc") rating2 = Rating(rating_id=3, stars=2, comments="def") rating3 = Rating(rating_id=3, stars=3, comments="ghi") ratings = [rating1, rating2, rating3] self.assertEqual(calc_avg_star_rating(ratings), 3)
def show_product_ratings(prod_id): """Shows product star ratings and any comments.""" item = Product.query.get(prod_id) histories = History.query.filter(History.prod_id == prod_id).all() product_ratings = [] for history in histories: if history.product_rating: product_ratings.append(history.product_rating) avg_star_rating = calc_avg_star_rating(product_ratings) return render_template("show-product-ratings.html", ratings=product_ratings, average=avg_star_rating, product=item)
def show_renter_ratings(renter_id): """Shows renter star ratings and any comments.""" histories = History.query.filter(History.renter_user_id == renter_id).all() renter = User.query.get(renter_id) renter_ratings = [] for history in histories: if history.renter_rating: renter_ratings.append(history.renter_rating) avg_star_rating = calc_avg_star_rating(renter_ratings) return render_template("show-renter-ratings.html", ratings=renter_ratings, average=avg_star_rating, user=renter)
def show_owner_ratings(user_id): """Shows owner star ratings and any comments.""" owner = User.query.get(user_id) products = owner.products owner_ratings = [] # Ratings are optional, so we have to check if there are any. for product in products: for history in product.histories: if history.owner_rating: owner_ratings.append(history.owner_rating) avg_star_rating = calc_avg_star_rating(owner_ratings) return render_template("show-owner-ratings.html", ratings=owner_ratings, average=avg_star_rating, prod=product)
def show_product_ratings(prod_id): """Shows product star ratings and any comments.""" item = Product.query.get(prod_id) histories = History.query.filter(History.prod_id == prod_id).all() product_ratings = [] for history in histories: if history.product_rating: product_ratings.append(history.product_rating) avg_star_rating = calc_avg_star_rating(product_ratings) return render_template("show-product-ratings.html", ratings=product_ratings, average=avg_star_rating, product=item)
def show_renter_ratings(renter_id): """Shows renter star ratings and any comments.""" histories = History.query.filter(History.renter_user_id == renter_id).all() renter = User.query.get(renter_id) renter_ratings = [] for history in histories: if history.renter_rating: renter_ratings.append(history.renter_rating) avg_star_rating = calc_avg_star_rating(renter_ratings) return render_template("show-renter-ratings.html", ratings=renter_ratings, average=avg_star_rating, user=renter)
def show_owner_ratings(user_id): """Shows owner star ratings and any comments.""" owner = User.query.get(user_id) products = owner.products owner_ratings = [] # Ratings are optional, so we have to check if there are any. for product in products: for history in product.histories: if history.owner_rating: owner_ratings.append(history.owner_rating) avg_star_rating = calc_avg_star_rating(owner_ratings) return render_template("show-owner-ratings.html", ratings=owner_ratings, average=avg_star_rating, prod=product)