From 13c13440130eb907df990cffb6e908eadde1c553 Mon Sep 17 00:00:00 2001 From: candifloss Date: Sat, 8 Feb 2025 01:28:37 +0530 Subject: [PATCH] Fixed primary key in update.py --- routes/update.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/routes/update.py b/routes/update.py index e29ccf2..6745040 100644 --- a/routes/update.py +++ b/routes/update.py @@ -5,11 +5,21 @@ from sqlalchemy import exc # Import exc for database exceptions update_bp = Blueprint('editasset', __name__) -@update_bp.route('/update//', methods=['GET', 'POST']) -def update(assettag): - item = Asset.query.filter_by(assettag=assettag).first() +@update_bp.route('/update//', methods=['GET', 'POST']) +def update(primary_value): + # Identify the primary attribute + primary_attrib = next( + (attrib for attrib, config in item_attributes.items() if config.primary), + None + ) + + if not primary_attrib: + return "Primary attribute not defined in configuration." + + # Fetch the item using the primary attribute + item = Asset.query.filter_by(**{primary_attrib: primary_value}).first() if not item: - return f"Asset {assettag} is not found" + return f"{item_attributes[primary_attrib].display_name} '{primary_value}' not found." # Move this to a template if request.method == 'GET': return render_template('update.html', item=item, item_attributes=item_attributes)