
- Created a new Blueprint for main routes in `routes/__init__.py`. - Implemented inventory listing and item management in `routes/inventory.py`. - Added user listing and detail views in `routes/user.py`. - Developed worklog listing and entry views in `routes/worklog.py`. - Introduced search functionality across inventory, users, and worklogs in `routes/search.py`. - Established settings management for brands, items, rooms, and functions in `routes/settings.py`. - Enhanced helper functions for rendering headers and managing data in `routes/helpers.py`. - Updated index route to display active worklogs and inventory conditions in `routes/index.py`.
86 lines
No EOL
2.4 KiB
Python
86 lines
No EOL
2.4 KiB
Python
from flask import render_template
|
|
import pandas as pd
|
|
|
|
from . import main
|
|
from .helpers import worklog_headers
|
|
from .. import db
|
|
from ..models import WorkLog, Inventory
|
|
from ..utils.load import eager_load_worklog_relationships, eager_load_inventory_relationships
|
|
|
|
@main.route("/")
|
|
def index():
|
|
worklog_query = eager_load_worklog_relationships(
|
|
db.session.query(WorkLog)
|
|
).filter(
|
|
(WorkLog.complete == False)
|
|
)
|
|
|
|
active_worklogs = worklog_query.all()
|
|
|
|
active_count = len(active_worklogs)
|
|
active_worklog_headers = {
|
|
k: v for k, v in worklog_headers.items()
|
|
if k not in ['End Time', 'Quick Analysis?', 'Complete?', 'Follow Up?']
|
|
}
|
|
|
|
inventory_query = eager_load_inventory_relationships(
|
|
db.session.query(Inventory)
|
|
)
|
|
|
|
results = inventory_query.all()
|
|
|
|
data = [{
|
|
'id': item.id,
|
|
'condition': item.condition
|
|
} for item in results]
|
|
|
|
df = pd.DataFrame(data)
|
|
|
|
# Count items per condition
|
|
expected_conditions = [
|
|
'Deployed','Inoperable', 'Partially Inoperable',
|
|
'Unverified', 'Working'
|
|
]
|
|
print(df)
|
|
if 'condition' in df.columns:
|
|
pivot = df['condition'].value_counts().reindex(expected_conditions, fill_value=0)
|
|
else:
|
|
pivot = pd.Series([0] * len(expected_conditions), index=expected_conditions)
|
|
|
|
# Convert pandas/numpy int64s to plain old Python ints
|
|
pivot = pivot.astype(int)
|
|
labels = list(pivot.index)
|
|
data = [int(x) for x in pivot.values]
|
|
|
|
datasets = [{
|
|
'type': 'pie',
|
|
'labels': labels,
|
|
'values': data,
|
|
'name': 'Inventory Conditions'
|
|
}]
|
|
|
|
active_worklog_rows = []
|
|
for log in active_worklogs:
|
|
# Create a dictionary of {column name: cell dict}
|
|
cells_by_key = {k: fn(log) for k, fn in worklog_headers.items()}
|
|
|
|
# Use original, full header set for logic
|
|
highlight = cells_by_key.get("Follow Up?", {}).get("highlight", False)
|
|
|
|
# Use only filtered headers — and in exact order
|
|
cells = [cells_by_key[k] for k in active_worklog_headers]
|
|
|
|
active_worklog_rows.append({
|
|
"id": log.id,
|
|
"cells": cells,
|
|
"highlight": highlight
|
|
})
|
|
|
|
return render_template(
|
|
"index.html",
|
|
active_count=active_count,
|
|
active_worklog_headers=active_worklog_headers,
|
|
active_worklog_rows=active_worklog_rows,
|
|
labels=labels,
|
|
datasets=datasets
|
|
) |