flask_crud_app/routes/viewall.py

23 lines
761 B
Python
Raw Permalink Normal View History

2025-02-11 07:47:57 +00:00
from flask import Blueprint, render_template
2025-02-11 18:45:53 +00:00
from definitions.models import Asset
from config import item_attributes
2025-01-30 07:37:21 +00:00
viewall_bp = Blueprint('viewall', __name__)
2025-02-11 07:47:57 +00:00
@viewall_bp.route('/viewall/', methods=['GET'])
2025-01-30 07:37:21 +00:00
def view_list():
# Fetch all items from the database
2025-01-30 07:37:21 +00:00
items = Asset.query.all()
# Identify the primary attribute
primary_attrib = next((attrib for attrib in item_attributes if attrib.primary), None)
if not primary_attrib:
return "Primary attribute not defined in configuration."
# Render the template with items, attributes, and primary attribute
return render_template(
'viewList.html',
items=items,
item_attributes=item_attributes,
primary_attrib=primary_attrib.attrib_name
)