Updated flash commands to allow for differently styled boxes

This commit is contained in:
Luke Else 2024-01-27 22:08:15 +00:00
parent ce316eb9fd
commit 595069772c
3 changed files with 18 additions and 15 deletions

View File

@ -50,7 +50,10 @@ def category(category: str):
# No Products visible # No Products visible
if products is None: if products is None:
flash(f"No Products available. Try expanding your search criteria.") flash(
f"No Products available. Try expanding your search criteria.",
"warning"
)
return render_template( return render_template(
'index.html', 'index.html',
@ -68,7 +71,7 @@ def id(id: int):
# Check that a valid product was returned # Check that a valid product was returned
if product is None: if product is None:
flash(f"No Product available with id {id}") flash(f"No Product available with id {id}", "warning")
return redirect("/") return redirect("/")
print(product.name) print(product.name)
@ -86,7 +89,7 @@ def display_add_product():
# User needs to be logged in as a seller to view this page # User needs to be logged in as a seller to view this page
if not is_role("Seller"): if not is_role("Seller"):
flash("You must be logged in as a seller to view this page!") flash("You must be logged in as a seller to view this page!", "error")
return redirect("/") return redirect("/")
return render_template('index.html', content='new_product.html') return render_template('index.html', content='new_product.html')
@ -101,7 +104,7 @@ def add_product():
# User needs to be logged in as a seller to view this page # User needs to be logged in as a seller to view this page
if not is_role("Seller"): if not is_role("Seller"):
flash("You must be logged in as a seller to view this page!") flash("You must be logged in as a seller to view this page!", "error")
return redirect("/") return redirect("/")
file = request.files.get('image') file = request.files.get('image')
@ -132,14 +135,14 @@ def update_product(id: int):
# User needs to be logged in as a seller to view this page # User needs to be logged in as a seller to view this page
if not is_role("Seller"): if not is_role("Seller"):
flash("You must be logged in as a seller to view this page!") flash("You must be logged in as a seller to view this page!", "error")
return redirect("/") return redirect("/")
db = ProductController() db = ProductController()
product = db.read_id(id) product = db.read_id(id)
if product.sellerID != user_id: if product.sellerID != user_id:
flash("This product does not belong to you!") flash("This product does not belong to you!", "error")
return redirect("/ownproducts") return redirect("/ownproducts")
# Save new image file # Save new image file
@ -158,7 +161,7 @@ def update_product(id: int):
product.quantityAvailable = request.form.get('quantity') product.quantityAvailable = request.form.get('quantity')
db.update(product) db.update(product)
flash("Product successfully updated") flash("Product successfully updated", 'notice')
return redirect(f"/products/{product.id}") return redirect(f"/products/{product.id}")
@ -169,14 +172,14 @@ def display_own_products():
# User must be logged in as seller to view page # User must be logged in as seller to view page
if not is_role("Seller"): if not is_role("Seller"):
flash("You must be logged in as a seller to view this page!") flash("You must be logged in as a seller to view this page!", "error")
return redirect("/") return redirect("/")
db = ProductController() db = ProductController()
products = db.read_user(user_id) products = db.read_user(user_id)
if products is None: if products is None:
flash("You don't currently have any products for sale.") flash("You don't currently have any products for sale.", "info")
return render_template( return render_template(
'index.html', 'index.html',

View File

@ -31,13 +31,13 @@ def login():
# No user found # No user found
if user is None: if user is None:
error = "No user found with the username " + request.form['username'] error = "No user found with the username " + request.form['username']
flash(error) flash(error, 'warning')
return redirect("/login") return redirect("/login")
# Incorrect Password # Incorrect Password
if sha512(request.form['password'].encode()).hexdigest() != user.password: if sha512(request.form['password'].encode()).hexdigest() != user.password:
error = "Incorrect Password" error = "Incorrect Password"
flash(error) flash(error, 'warning')
return redirect("/login") return redirect("/login")
session['user_id'] = user.id session['user_id'] = user.id
@ -59,7 +59,7 @@ def signup():
# User already exists # User already exists
if database.read(request.form['username']) is not None: if database.read(request.form['username']) is not None:
error = "User, " + request.form['username'] + " already exists" error = "User, " + request.form['username'] + " already exists"
flash(error) flash(error, 'warning')
return redirect("/signup") return redirect("/signup")
# Signup as Seller or Customer # Signup as Seller or Customer

View File

@ -35,12 +35,12 @@
</centre> </centre>
</div> </div>
{% with messages = get_flashed_messages()%} {% with messages = get_flashed_messages(with_categories=true)%}
{% if messages %} {% if messages %}
{% for message in messages %} {% for category, message in messages %}
<label> <label>
<input type="checkbox" class="alertCheckbox" autocomplete="off" /> <input type="checkbox" class="alertCheckbox" autocomplete="off" />
<div class="alert error"> <div class="alert {{category}}">
<span class="alertClose">X</span> <span class="alertClose">X</span>
<span class="alertText">{{message}} <span class="alertText">{{message}}
<br class="clear"/></span> <br class="clear"/></span>