Updated viewall.py & viewList.html to use config
This commit is contained in:
parent
3762534c65
commit
48a07b7e31
@ -1,6 +1,7 @@
|
||||
from flask import Blueprint, request, render_template, send_file
|
||||
from models import Asset, db
|
||||
import csv
|
||||
from config import item_attributes
|
||||
|
||||
viewall_bp = Blueprint('viewall', __name__)
|
||||
|
||||
@ -16,4 +17,8 @@ def view_list():
|
||||
return send_file('inventory_export.csv', as_attachment=True)
|
||||
|
||||
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)
|
@ -9,42 +9,31 @@
|
||||
|
||||
<table border="1" align="center">
|
||||
<tr>
|
||||
<th>Asset Tag</th>
|
||||
<th>Host Name</th>
|
||||
<th>Warranty From</th>
|
||||
<th>Status</th>
|
||||
<th>Staff No.</th>
|
||||
<!-- Dynamically generate table headers -->
|
||||
{% for attrib, config in item_attributes.items() %}
|
||||
<th>{{ config.display_name }}</th>
|
||||
{% endfor %}
|
||||
<th colspan="2">Actions</th>
|
||||
</tr>
|
||||
{% for item in items %}
|
||||
|
||||
<!-- Dynamically generate table rows -->
|
||||
{% for item in items %}
|
||||
<tr>
|
||||
{% for attrib, config in item_attributes.items() %}
|
||||
<td>{{ item[attrib] }}</td>
|
||||
{% endfor %}
|
||||
<td>
|
||||
{{item.assettag}}
|
||||
</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">
|
||||
<form action="/update/{{ item[primary_attrib] }}" method="get">
|
||||
<button type="submit">Edit</button>
|
||||
</form>
|
||||
</td>
|
||||
<td>
|
||||
<form action="/delete/{{item.assettag}}" method="get">
|
||||
<form action="/delete/{{ item[primary_attrib] }}" method="get">
|
||||
<button type="submit">Delete</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
Loading…
Reference in New Issue
Block a user