2024-01-28 11:59:04 +00:00
|
|
|
from models.users.user import User
|
|
|
|
from controllers.database.user import UserController
|
|
|
|
|
|
|
|
from flask import redirect, Blueprint, session
|
|
|
|
|
|
|
|
from . import user
|
|
|
|
from . import product
|
2024-02-01 01:44:02 +00:00
|
|
|
from . import stats
|
2024-01-28 11:59:04 +00:00
|
|
|
|
|
|
|
blueprint = Blueprint('main', __name__)
|
|
|
|
|
|
|
|
blueprint.register_blueprint(user.blueprint)
|
|
|
|
blueprint.register_blueprint(product.blueprint)
|
2024-02-01 01:44:02 +00:00
|
|
|
blueprint.register_blueprint(stats.blueprint)
|
2024-01-28 11:59:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
# CONTEXTS #
|
|
|
|
|
|
|
|
# Function that returns a given user class based on the ID in the session
|
|
|
|
@blueprint.context_processor
|
|
|
|
def get_user() -> dict[User | None]:
|
|
|
|
# Get the user based on the user ID
|
|
|
|
user_id = session.get('user_id')
|
|
|
|
user = None
|
|
|
|
|
|
|
|
if user_id is not None:
|
|
|
|
db = UserController()
|
|
|
|
user = db.read_id(user_id)
|
|
|
|
|
|
|
|
return dict(user=user)
|
|
|
|
|
|
|
|
|
|
|
|
# Function responsible for displaying the main landing page of the site
|
|
|
|
@blueprint.route('/')
|
|
|
|
def index():
|
|
|
|
return redirect("/products")
|