#10 Added Product section to admin page
This commit is contained in:
@ -46,6 +46,8 @@ def products():
|
||||
db = ProductController()
|
||||
products = db.read_all()
|
||||
|
||||
print(len(products))
|
||||
|
||||
return render_template(
|
||||
"index.html",
|
||||
content="admin.html",
|
||||
|
@ -50,6 +50,13 @@ def get_filter():
|
||||
return FILTERS['Relevance']
|
||||
|
||||
|
||||
def redirect_on_complete():
|
||||
""" Redirects to an appropriate location depending on the role """
|
||||
if is_role("Admin"):
|
||||
return redirect(url_for('main.admin.products'))
|
||||
return redirect(url_for('main.seller.display_own'))
|
||||
|
||||
|
||||
@product_blueprint.context_processor
|
||||
@seller_blueprint.context_processor
|
||||
def category_list():
|
||||
@ -168,9 +175,10 @@ def update(id: int):
|
||||
db = ProductController()
|
||||
product = db.read_id(id)
|
||||
|
||||
if product.sellerID != user_id:
|
||||
# Only admins and the owner can change the product
|
||||
if product.sellerID != user_id and not is_role("Admin"):
|
||||
flash("This product does not belong to you!", "error")
|
||||
return redirect(url_for('main.seller.own'))
|
||||
return redirect(url_for('main.seller.display_own'))
|
||||
|
||||
# Save new image file
|
||||
file = request.files.get('image')
|
||||
@ -201,13 +209,13 @@ def delete(id: int):
|
||||
db = ProductController()
|
||||
product = db.read_id(id)
|
||||
|
||||
if product.sellerID != user_id:
|
||||
if product.sellerID != user_id and not is_role("Admin"):
|
||||
flash("This product does not belong to you!", "error")
|
||||
return redirect(url_for('main.seller.display_own'))
|
||||
|
||||
db.delete(id)
|
||||
flash("Product Removed!", "success")
|
||||
return redirect(url_for('main.seller.display_own'))
|
||||
return redirect_on_complete()
|
||||
|
||||
|
||||
@seller_blueprint.route('/ownproducts')
|
||||
|
@ -31,7 +31,7 @@ def view_product_stats(id: int):
|
||||
# Check user is seller
|
||||
if not is_role("Seller"):
|
||||
flash("You must be logged in as a seller to view this page!", "error")
|
||||
return redirect(url_for('main.index'))
|
||||
return redirect(url_for('main.products.product', id=id))
|
||||
|
||||
db = ProductController()
|
||||
product = db.read_id(id)
|
||||
|
Reference in New Issue
Block a user