This commit is contained in:
@ -69,12 +69,15 @@ def id(id: int):
|
||||
|
||||
# Check that a valid product was returned
|
||||
if product is None:
|
||||
flash("No Product available here")
|
||||
flash(f"No Product available with id {id}")
|
||||
return redirect("/")
|
||||
|
||||
print(product.name)
|
||||
return render_template('index.html', content='content.html', products = [product])
|
||||
return "ID: " + str(id)
|
||||
return render_template(
|
||||
'index.html',
|
||||
content='product.html',
|
||||
product=product
|
||||
)
|
||||
|
||||
|
||||
@blueprint.route('/add')
|
||||
@ -123,12 +126,44 @@ def add_product():
|
||||
datetime.now(),
|
||||
request.form.get('quantity')
|
||||
)
|
||||
|
||||
db = ProductController()
|
||||
db.create(product)
|
||||
|
||||
return redirect('/products/ownproducts')
|
||||
|
||||
|
||||
@blueprint.post('/update/<int:id>')
|
||||
def update_product(id: int):
|
||||
""" Processes a request to update 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!")
|
||||
return redirect("/")
|
||||
|
||||
db = ProductController()
|
||||
product = db.read_id(id)
|
||||
|
||||
if product.sellerID != user_id:
|
||||
flash("This product does not belong to you!")
|
||||
return redirect("/ownproducts")
|
||||
|
||||
# Update product details
|
||||
product.name = request.form.get('name')
|
||||
product.description = request.form.get('description')
|
||||
product.category = request.form.get('category')
|
||||
product.image = request.form.get('image')
|
||||
product.cost = request.form.get('cost')
|
||||
product.quantityAvailable = request.form.get('quantity')
|
||||
|
||||
db.update(product)
|
||||
flash("Product successfully updated")
|
||||
return redirect(f"/{product.id}")
|
||||
|
||||
|
||||
@blueprint.route('/ownproducts')
|
||||
def display_own_products():
|
||||
""" Display products owned by the currently logged in seller """
|
||||
|
Reference in New Issue
Block a user