Added ability for stats to be tracked on products

This commit is contained in:
2024-01-30 21:49:17 +00:00
parent dfb33e195c
commit e27ed02028
4 changed files with 145 additions and 6 deletions

View File

@ -6,15 +6,15 @@
from flask import render_template, session, flash, request, redirect, Blueprint
from models.products.product import Product
from models.stats import Stats
from controllers.database.product import ProductController
from controllers.database.category import CategoryController
from controllers.database.user import UserController
from controllers.database.stats import StatsController
from datetime import datetime
from utils.file_utils import allowed_file, save_image, remove_file
from utils.file_utils import save_image, remove_file
from utils.user_utils import is_role
import pathlib
import os
blueprint = Blueprint("products", __name__, url_prefix="/products")
@ -74,6 +74,12 @@ def id(id: int):
flash(f"No Product available with id {id}", "warning")
return redirect("/")
# Record a view on the product
db = StatsController()
user_id = session.get('user_id')
print(user_id)
db.create(Stats(product.id, user_id))
return render_template(
'index.html',
content='product.html',
@ -84,8 +90,6 @@ def id(id: int):
@blueprint.route('/add')
def display_add_product():
""" Launches the page to add a new product to the site """
user_id = session.get('user_id')
# User needs to be logged in as a seller to view this page
if not is_role("Seller"):
flash("You must be logged in as a seller to view this page!", "error")