#9 Delete Product box now available
This commit is contained in:
@ -146,7 +146,7 @@ def update_product(id: int):
|
||||
|
||||
if product.sellerID != user_id:
|
||||
flash("This product does not belong to you!", "error")
|
||||
return redirect("/ownproducts")
|
||||
return redirect("/products/ownproducts")
|
||||
|
||||
# Save new image file
|
||||
file = request.files.get('image')
|
||||
@ -168,6 +168,29 @@ def update_product(id: int):
|
||||
return redirect(f"/products/{product.id}")
|
||||
|
||||
|
||||
@blueprint.post('/delete/<int:id>')
|
||||
def delete_product(id: int):
|
||||
""" Processes a request to delete a product in place on the site """
|
||||
# Ensure that the product belongs to the current user
|
||||
user_id = session.get('user_id')
|
||||
|
||||
# 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!", "error")
|
||||
return redirect("/")
|
||||
|
||||
db = ProductController()
|
||||
product = db.read_id(id)
|
||||
|
||||
if product.sellerID != user_id:
|
||||
flash("This product does not belong to you!", "error")
|
||||
return redirect("/products/ownproducts")
|
||||
|
||||
db.delete(id)
|
||||
flash("Product Removed!", "success")
|
||||
return redirect("/products/ownproducts")
|
||||
|
||||
|
||||
@blueprint.route('/ownproducts')
|
||||
def display_own_products():
|
||||
""" Display products owned by the currently logged in seller """
|
||||
|
Reference in New Issue
Block a user