From a944bd9384708be2d8718ae6c37d1dde055a8c03 Mon Sep 17 00:00:00 2001 From: candifloss Date: Tue, 25 Feb 2025 01:07:28 +0530 Subject: [PATCH] Added preview before deleting item --- routes/delete.py | 18 +++++++++++++----- templates/delete.html | 25 +++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/routes/delete.py b/routes/delete.py index 11dff6c..bb49718 100644 --- a/routes/delete.py +++ b/routes/delete.py @@ -1,10 +1,10 @@ -from flask import Blueprint, request, render_template, redirect, abort +from flask import Blueprint, request, render_template, redirect, flash from definitions.models import Asset, db from config import item_attributes delete_bp = Blueprint('deleteasset', __name__) -@delete_bp.route('/delete//', methods=['GET', 'POST']) +@delete_bp.route('/delete//', methods=['GET', 'POST']) def delete(primary_value): # Identify the primary attribute primary_attrib = next( @@ -13,16 +13,24 @@ def delete(primary_value): ) if not primary_attrib: - return "Primary attribute not defined in configuration." + flash("Primary attribute not defined in configuration.", "error") + return redirect('/viewall') # Fetch the item using the primary attribute item = Asset.query.filter_by(**{primary_attrib.attrib_name: primary_value}).first() if not item: - abort(404) # Item not found + flash("Item not found.", "error") + return redirect('/viewall') if request.method == 'POST': db.session.delete(item) db.session.commit() + flash("Item successfully deleted.", "success") return redirect('/viewall') - return render_template('delete.html', item=item) \ No newline at end of file + # Render the delete confirmation page with a preview of the item + return render_template( + 'delete.html', + item=item, + item_attributes=item_attributes + ) \ No newline at end of file diff --git a/templates/delete.html b/templates/delete.html index 0313110..cbc9159 100644 --- a/templates/delete.html +++ b/templates/delete.html @@ -5,10 +5,31 @@ Delete Item +

Are you sure you want to delete the item?

+ +
- Do you want to delete the item? - +
+ Cancel
+ + + + + + + + + + + {% for attrib in item_attributes %} + + + + + {% endfor %} + +
AttributeValue
{{ attrib.display_name }}{{ item[attrib.attrib_name] }}
\ No newline at end of file