2024-01-05 18:20:56 +00:00
|
|
|
from flask import Blueprint
|
|
|
|
|
2024-01-05 21:42:27 +00:00
|
|
|
from flask import render_template, session, flash
|
2024-01-05 18:20:56 +00:00
|
|
|
from controllers.database.product import ProductController
|
2024-01-06 01:14:20 +00:00
|
|
|
from controllers.database.category import CategoryController
|
2024-01-05 18:20:56 +00:00
|
|
|
|
|
|
|
blueprint = Blueprint("products", __name__, url_prefix="/products")
|
|
|
|
|
2024-01-07 13:47:09 +00:00
|
|
|
# Global context to enable the categories to be accessed
|
|
|
|
# from any view
|
2024-01-06 01:14:20 +00:00
|
|
|
@blueprint.context_processor
|
|
|
|
def category_list():
|
|
|
|
database = CategoryController()
|
|
|
|
categories = database.read_all()
|
|
|
|
return dict(categories=categories)
|
|
|
|
|
2024-01-05 21:40:32 +00:00
|
|
|
# Loads the front product page
|
2024-01-05 18:20:56 +00:00
|
|
|
@blueprint.route('/')
|
|
|
|
def index():
|
|
|
|
database = ProductController()
|
|
|
|
products = database.read_all()
|
|
|
|
|
|
|
|
# No Products visible
|
|
|
|
if products == None:
|
|
|
|
flash("No Products available")
|
|
|
|
|
2024-01-05 21:40:32 +00:00
|
|
|
return render_template('index.html', content="content.html", user = session.get('user'), products = products)
|
|
|
|
|
|
|
|
# Loads a given product category page
|
|
|
|
@blueprint.route('/<string:category>')
|
|
|
|
def category(category: str):
|
2024-01-06 01:14:20 +00:00
|
|
|
print(category)
|
|
|
|
database = ProductController()
|
|
|
|
products = database.read_all(category)
|
|
|
|
|
|
|
|
# No Products visible
|
|
|
|
if products == None:
|
|
|
|
flash("No Products available in " + category)
|
|
|
|
|
|
|
|
return render_template('index.html', content="content.html", user = session.get('user'), products = products, category = category)
|
2024-01-05 21:40:32 +00:00
|
|
|
|
|
|
|
# Loads a given product based on ID
|
|
|
|
@blueprint.route('/<int:id>')
|
|
|
|
def id(id: int):
|
|
|
|
return "ID: " + str(id)
|
|
|
|
|