2024-01-19 11:57:53 +00:00
|
|
|
from models.users.user import User
|
|
|
|
from controllers.database.user import UserController
|
|
|
|
|
|
|
|
from flask import redirect, Blueprint, session
|
2023-12-27 21:36:53 +00:00
|
|
|
|
2024-01-05 18:20:56 +00:00
|
|
|
from . import user
|
|
|
|
from . import product
|
2023-12-31 19:03:29 +00:00
|
|
|
|
2024-01-05 18:20:56 +00:00
|
|
|
blueprint = Blueprint('main', __name__)
|
2023-12-31 19:03:29 +00:00
|
|
|
|
2024-01-05 18:20:56 +00:00
|
|
|
blueprint.register_blueprint(user.blueprint)
|
|
|
|
blueprint.register_blueprint(product.blueprint)
|
2023-12-31 19:03:29 +00:00
|
|
|
|
2024-01-19 11:57:53 +00:00
|
|
|
|
2024-01-21 22:22:29 +00:00
|
|
|
# CONTEXTS #
|
2024-01-19 11:57:53 +00:00
|
|
|
|
|
|
|
# Function that returns a given user class based on the ID in the session
|
|
|
|
@blueprint.context_processor
|
2024-01-21 22:06:06 +00:00
|
|
|
def get_user() -> dict[User | None]:
|
2024-01-19 11:57:53 +00:00
|
|
|
# Get the user based on the user ID
|
|
|
|
user_id = session.get('user_id')
|
|
|
|
user = None
|
2024-01-21 22:06:06 +00:00
|
|
|
|
2024-01-21 22:22:29 +00:00
|
|
|
if user_id is not None:
|
2024-01-19 11:57:53 +00:00
|
|
|
db = UserController()
|
|
|
|
user = db.read_id(user_id)
|
2024-01-21 22:06:06 +00:00
|
|
|
|
2024-01-19 11:57:53 +00:00
|
|
|
return dict(user=user)
|
|
|
|
|
|
|
|
|
2024-01-05 18:20:56 +00:00
|
|
|
# Function responsible for displaying the main landing page of the site
|
|
|
|
@blueprint.route('/')
|
|
|
|
def index():
|
|
|
|
return redirect("/products")
|