REFACTOR: Changed blueprints to allow for preprocessing of requests
This commit is contained in:
@@ -2,14 +2,27 @@
|
||||
in the web app
|
||||
"""
|
||||
|
||||
from flask import render_template, Blueprint
|
||||
from flask import render_template, Blueprint, redirect, url_for, flash
|
||||
|
||||
from controllers.database.user import UserController
|
||||
from controllers.database.product import ProductController
|
||||
|
||||
from utils.user_utils import is_role
|
||||
|
||||
# Blueprint to append user endpoints to
|
||||
blueprint = Blueprint("admin", __name__, url_prefix="/admin")
|
||||
|
||||
|
||||
@blueprint.before_request
|
||||
def check_admin_user():
|
||||
""" Preprocess for all admin endpoints to ensure that the requesting
|
||||
user is logged in as an 'Admin'
|
||||
"""
|
||||
if not is_role("Admin"):
|
||||
flash("You must be logged in as an Admin to view this page.", "error")
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
|
||||
@blueprint.route('/')
|
||||
def main():
|
||||
""" Function responsible for delivering the admin page for the site """
|
||||
@@ -24,3 +37,17 @@ def users():
|
||||
users = db.read_all()
|
||||
|
||||
return render_template("index.html", content="admin.html", users=users)
|
||||
|
||||
|
||||
@blueprint.route('/products/')
|
||||
def products():
|
||||
""" Endpoint responsible for managing products on the site """
|
||||
# Get all products to create admin table on frontend
|
||||
db = ProductController()
|
||||
products = db.read_all()
|
||||
|
||||
return render_template(
|
||||
"index.html",
|
||||
content="admin.html",
|
||||
products=products
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user