def product(product_id): p = get_product_by_id(product_id) user_id = session['user_id'] rating = get_rating_by_both(user_id, product_id) review = rating.review if rating else 0 emotion = rating.emotion if rating else None similar_products = p.get_similar_products(9) similar_ratings = [ get_rating_by_both(user_id, p.id) for p in similar_products ] print(similar_products) img = os.path.basename(p.image) return render_template("product/product.html", product=p, img=img, similar_products=similar_products, similar_ratings=similar_ratings, review=review, emotion=emotion, os=os, zip=zip, remove_starting_digits=remove_starting_digits)
def recommended(): user_id = session.get("user_id") if user_id is None: return redirect_previous_url() user = get_user_by_id(user_id) products = user.get_recommended_products() ratings = [get_rating_by_both(user_id, p.id) for p in products] tags = get_product_tags() return render_template("index.html", products=products, ratings=ratings, tags=tags, chosen_products=products[:5], os=os, zip=zip, len=len, range=range, enumerate=enumerate, remove_starting_digits=remove_starting_digits)
def categories(category): products = get_products_by_tag(category) tags = get_product_tags() if session.get("user_id"): user_id = session.get("user_id") ratings = [get_rating_by_both(user_id, p.id) for p in products] else: ratings = [None] * len(products) return render_template("index.html", products=products, ratings=ratings, tags=tags, category=category, chosen_products=products[:5], os=os, zip=zip, len=len, range=range, enumerate=enumerate, remove_starting_digits=remove_starting_digits)
def search(): query = request.args.get("q") products = get_products_by_search_query(query) if session.get("user_id"): user_id = session.get("user_id") ratings = [get_rating_by_both(user_id, p.id) for p in products] else: ratings = [None] * len(products) tags = get_product_tags() return render_template("index.html", products=products, ratings=ratings, tags=tags, chosen_products=products[:5], os=os, zip=zip, len=len, range=range, enumerate=enumerate, remove_starting_digits=remove_starting_digits)
def home(): products = get_all_products() sorted_products = products.copy() random.shuffle(products) if session.get("user_id"): user_id = session.get("user_id") ratings = [get_rating_by_both(user_id, p.id) for p in products] else: ratings = [None] * len(products) tags = get_product_tags() return render_template("index.html", products=products, ratings=ratings, tags=tags, chosen_products=sorted_products[:5], os=os, len=len, range=range, enumerate=enumerate, zip=zip, remove_starting_digits=remove_starting_digits)