Updated viewall.py & viewList.html to use config

This commit is contained in:
Candifloss 2025-02-11 11:08:27 +05:30
parent 3762534c65
commit 48a07b7e31
2 changed files with 20 additions and 26 deletions

View File

@ -1,6 +1,7 @@
from flask import Blueprint, request, render_template, send_file from flask import Blueprint, request, render_template, send_file
from models import Asset, db from models import Asset, db
import csv import csv
from config import item_attributes
viewall_bp = Blueprint('viewall', __name__) viewall_bp = Blueprint('viewall', __name__)
@ -16,4 +17,8 @@ def view_list():
return send_file('inventory_export.csv', as_attachment=True) return send_file('inventory_export.csv', as_attachment=True)
items = Asset.query.all() items = Asset.query.all()
return render_template('viewList.html', items=items) primary_attrib = next(
(attrib for attrib, config in item_attributes.items() if config.primary),
None
)
return render_template('viewList.html', items=items, item_attributes=item_attributes, primary_attrib=primary_attrib)

View File

@ -9,42 +9,31 @@
<table border="1" align="center"> <table border="1" align="center">
<tr> <tr>
<th>Asset Tag</th> <!-- Dynamically generate table headers -->
<th>Host Name</th> {% for attrib, config in item_attributes.items() %}
<th>Warranty From</th> <th>{{ config.display_name }}</th>
<th>Status</th> {% endfor %}
<th>Staff No.</th> <th colspan="2">Actions</th>
</tr> </tr>
{% for item in items %}
<!-- Dynamically generate table rows -->
{% for item in items %}
<tr> <tr>
{% for attrib, config in item_attributes.items() %}
<td>{{ item[attrib] }}</td>
{% endfor %}
<td> <td>
{{item.assettag}} <form action="/update/{{ item[primary_attrib] }}" method="get">
</td>
<td>
{{item.hostname}}
</td>
<td>
{{item.warrantyfrom}}
</td>
<td>
{{item.status}}
</td>
<td>
{{item.staffnum}}
</td>
<td>
<form action="/update/{{item.assettag}}" method="get">
<button type="submit">Edit</button> <button type="submit">Edit</button>
</form> </form>
</td> </td>
<td> <td>
<form action="/delete/{{item.assettag}}" method="get"> <form action="/delete/{{ item[primary_attrib] }}" method="get">
<button type="submit">Delete</button> <button type="submit">Delete</button>
</form> </form>
</td> </td>
</tr> </tr>
{% endfor %}
{% endfor %}
</table> </table>
<br> <br>