Add routes and functionality for inventory management, user management, worklogs, and settings
- 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`.
This commit is contained in:
parent
4c36621eba
commit
4d8d5b4e6a
9 changed files with 684 additions and 630 deletions
66
routes/user.py
Normal file
66
routes/user.py
Normal file
|
@ -0,0 +1,66 @@
|
|||
from flask import render_template
|
||||
|
||||
from . import main
|
||||
from .helpers import ACTIVE_STATUSES, user_headers, inventory_headers, worklog_headers
|
||||
from .. import db
|
||||
from ..utils.load import eager_load_user_relationships, eager_load_room_relationships, eager_load_inventory_relationships, eager_load_worklog_relationships
|
||||
from ..models import User, Room, Inventory, WorkLog
|
||||
|
||||
@main.route("/users")
|
||||
def list_users():
|
||||
query = eager_load_user_relationships(db.session.query(User)).order_by(User.last_name, User.first_name)
|
||||
users = query.all()
|
||||
return render_template(
|
||||
'table.html',
|
||||
header = user_headers,
|
||||
rows = [{"id": user.id, "cells": [fn(user) for fn in user_headers.values()]} for user in users],
|
||||
title = "Users",
|
||||
entry_route = 'user'
|
||||
)
|
||||
|
||||
@main.route("/user/<id>")
|
||||
def user(id):
|
||||
try:
|
||||
id = int(id)
|
||||
except ValueError:
|
||||
return render_template('error.html', title='Bad ID', message='ID must be an integer.', endpoint='user', endpoint_args={'id': -1})
|
||||
|
||||
users_query = db.session.query(User).order_by(User.first_name, User.last_name)
|
||||
users = eager_load_user_relationships(users_query).all()
|
||||
user = next((u for u in users if u.id == id), None)
|
||||
rooms_query = db.session.query(Room)
|
||||
rooms = eager_load_room_relationships(rooms_query).all()
|
||||
inventory_query = (
|
||||
eager_load_inventory_relationships(db.session.query(Inventory))
|
||||
.filter(Inventory.owner_id == id) # type: ignore
|
||||
.filter(Inventory.condition.in_(ACTIVE_STATUSES))
|
||||
)
|
||||
|
||||
inventory = inventory_query.all()
|
||||
filtered_inventory_headers = {k: v for k, v in inventory_headers.items() if k not in ['Date Entered', 'Inventory #', 'Serial #',
|
||||
'Bar Code #', 'Condition', 'Owner', 'Notes',
|
||||
'Brand', 'Model', 'Shared?', 'Location']}
|
||||
worklog_query = eager_load_worklog_relationships(db.session.query(WorkLog)).filter(WorkLog.contact_id == id)
|
||||
worklog = worklog_query.order_by(WorkLog.start_time.desc()).all()
|
||||
filtered_worklog_headers = {k: v for k, v in worklog_headers.items() if k not in ['Contact', 'Follow Up?', 'Quick Analysis?']}
|
||||
|
||||
if user:
|
||||
title = f"User Record - {user.full_name}" if user.active else f"User Record - {user.full_name} (Inactive)"
|
||||
else:
|
||||
title = f"User Record - User Not Found"
|
||||
return render_template(
|
||||
'error.html',
|
||||
title=title,
|
||||
message=f"User with id {id} not found!"
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"user.html",
|
||||
title=title,
|
||||
user=user, users=users, rooms=rooms, assets=inventory,
|
||||
inventory_headers=filtered_inventory_headers,
|
||||
inventory_rows=[{"id": item.id, "cells": [fn(item) for fn in filtered_inventory_headers.values()]} for item in inventory],
|
||||
worklog=worklog,
|
||||
worklog_headers=filtered_worklog_headers,
|
||||
worklog_rows=[{"id": log.id, "cells": [fn(log) for fn in filtered_worklog_headers.values()]} for log in worklog]
|
||||
)
|
Loading…
Add table
Add a link
Reference in a new issue