Refactor worklog handling and table rendering in templates for improved clarity and performance

This commit is contained in:
Yaro Kasear 2025-06-16 16:24:41 -05:00
parent 25e67cce28
commit bdd2a43c8b
6 changed files with 40 additions and 58 deletions

View file

@ -131,7 +131,6 @@ def render_paginated_table(
@main.route("/")
def index():
stale_worklog_page = request.args.get('stale_worklog_page', 1, int)
cutoff = datetime.utcnow() - timedelta(days=14)
worklog_query = eager_load_worklog_relationships(
@ -140,8 +139,9 @@ def index():
(WorkLog.start_time < cutoff) & (WorkLog.complete == False)
)
stale_pagination = make_paginated_data(worklog_query, stale_worklog_page, 3)
stale_count = len(worklog_query.all())
stale_worklogs = worklog_query.all()
stale_count = len(stale_worklogs)
stale_worklog_headers = {
k: v for k, v in worklog_headers.items()
if k not in ['End Time', 'Quick Analysis?', 'Complete?', 'Follow Up?']
@ -182,13 +182,12 @@ def index():
return render_template(
"index.html",
title="Inventory Manager",
stale_pagination=stale_pagination,
stale_count=stale_count,
stale_worklog_headers=stale_worklog_headers,
stale_worklog_rows=[{
"id": log.id,
"cells": [fn(log) for fn in stale_worklog_headers.values()]
} for log in stale_pagination['items']],
} for log in stale_worklogs],
labels=labels,
datasets=datasets
)
@ -236,17 +235,15 @@ def list_inventory():
else:
return "Invalid filter_by parameter", 400
inventory = query.all()
return render_paginated_table(
query=query,
page=page,
return render_template(
'table.html',
title=f"Inventory Listing ({filter_name})" if filter_by else "Inventory Listing",
headers=inventory_headers,
row_fn=lambda i: [fn(i) for fn in inventory_headers.values()],
endpoint="main.list_inventory",
entry_route="inventory_item",
breadcrumb=[{'label': 'Inventory', 'url': url_for('main.inventory_index')}],
extra_args={'filter_by': filter_by, 'id': id}
header=inventory_headers,
rows=[{"id": item.id, "cells": [row_fn(item) for row_fn in inventory_headers.values()]} for item in inventory],
entry_route = 'inventory_item'
)
@main.route("/inventory/index")