Fixed primary key in update.py
This commit is contained in:
parent
fc93e6b716
commit
13c1344013
@ -5,11 +5,21 @@ from sqlalchemy import exc # Import exc for database exceptions
|
||||
|
||||
update_bp = Blueprint('editasset', __name__)
|
||||
|
||||
@update_bp.route('/update/<string:assettag>/', methods=['GET', 'POST'])
|
||||
def update(assettag):
|
||||
item = Asset.query.filter_by(assettag=assettag).first()
|
||||
@update_bp.route('/update/<string:primary_value>/', 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)
|
||||
|
Loading…
Reference in New Issue
Block a user