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
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(
'index.html',
@ -68,7 +71,7 @@ def id(id: int):
# Check that a valid product was returned
if product is None:
flash(f"No Product available with id {id}")
flash(f"No Product available with id {id}", "warning")
return redirect("/")
print(product.name)
@ -86,7 +89,7 @@ def display_add_product():
# User needs to be logged in as a seller to view this page
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 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
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("/")
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
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("/")
db = ProductController()
product = db.read_id(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")
# Save new image file
@ -158,7 +161,7 @@ def update_product(id: int):
product.quantityAvailable = request.form.get('quantity')
db.update(product)
flash("Product successfully updated")
flash("Product successfully updated", 'notice')
return redirect(f"/products/{product.id}")
@ -169,14 +172,14 @@ def display_own_products():
# User must be logged in as seller to view page
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("/")
db = ProductController()
products = db.read_user(user_id)
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(
'index.html',

View File

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

View File

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