Added preview before deleting item
This commit is contained in:
parent
5c22dbcc31
commit
a944bd9384
@ -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/<string:primary_value>/', methods=['GET', 'POST'])
|
||||
@delete_bp.route('/delete/<path:primary_value>/', 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)
|
||||
# Render the delete confirmation page with a preview of the item
|
||||
return render_template(
|
||||
'delete.html',
|
||||
item=item,
|
||||
item_attributes=item_attributes
|
||||
)
|
@ -5,10 +5,31 @@
|
||||
<title>Delete Item</title>
|
||||
</head>
|
||||
<body align="center">
|
||||
<h2>Are you sure you want to delete the item?</h2>
|
||||
|
||||
<!-- Confirmation form -->
|
||||
<form action='' method="post">
|
||||
Do you want to delete the item?
|
||||
<input type = "submit" value="Confirm">
|
||||
<br>
|
||||
<input type="submit" value="Delete">
|
||||
<a href='/viewall'>Cancel</a>
|
||||
</form>
|
||||
|
||||
<!-- Display a preview of the item -->
|
||||
<table border="1" align="center">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Attribute</th>
|
||||
<th>Value</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for attrib in item_attributes %}
|
||||
<tr>
|
||||
<td>{{ attrib.display_name }}</td>
|
||||
<td>{{ item[attrib.attrib_name] }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user