Add title field to User model and update related views for user management
This commit is contained in:
parent
fd148eb484
commit
f89b825ef0
6 changed files with 94 additions and 14 deletions
|
|
@ -52,6 +52,7 @@ FILTER_MAP = {
|
|||
user_headers = {
|
||||
"Last Name": lambda i: {"text": i.last_name},
|
||||
"First Name": lambda i: {"text": i.first_name},
|
||||
"Title": lambda i: {"text": i.title},
|
||||
"Supervisor": lambda i: {"text": i.supervisor.identifier, "url": url_for("main.user", id=i.supervisor.id)} if i.supervisor else {"text": None},
|
||||
"Location": lambda i: {"text": i.location.identifier} if i.location else {"text": None},
|
||||
"Staff?": lambda i: {"text": i.staff, "type": "bool", "html": checked_box if i.staff else unchecked_box},
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ def search():
|
|||
|
||||
if not query:
|
||||
return redirect(url_for('main.index'))
|
||||
|
||||
|
||||
InventoryAlias = aliased(Inventory)
|
||||
UserAlias = aliased(User)
|
||||
|
||||
|
|
@ -25,15 +25,18 @@ def search():
|
|||
Inventory.barcode.ilike(f"%{query}%"),
|
||||
Inventory.notes.ilike(f"%{query}%"),
|
||||
UserAlias.first_name.ilike(f"%{query}%"),
|
||||
UserAlias.last_name.ilike(f"%{query}%")
|
||||
UserAlias.last_name.ilike(f"%{query}%"),
|
||||
UserAlias.title.ilike(f"%{query}%")
|
||||
))
|
||||
inventory_results = inventory_query.all()
|
||||
user_query = eager_load_user_relationships(db.session.query(User).join(UserAlias, User.supervisor)).filter(
|
||||
or_(
|
||||
User.first_name.ilike(f"%{query}%"),
|
||||
User.last_name.ilike(f"%{query}%"),
|
||||
User.title.ilike(f"%{query}%"),
|
||||
UserAlias.first_name.ilike(f"%{query}%"),
|
||||
UserAlias.last_name.ilike(f"%{query}%")
|
||||
UserAlias.last_name.ilike(f"%{query}%"),
|
||||
UserAlias.title.ilike(f"%{query}%")
|
||||
))
|
||||
user_results = user_query.all()
|
||||
worklog_query = eager_load_worklog_relationships(db.session.query(WorkLog).join(UserAlias, WorkLog.contact).join(InventoryAlias, WorkLog.work_item)).filter(
|
||||
|
|
@ -41,26 +44,27 @@ def search():
|
|||
WorkLog.notes.ilike(f"%{query}%"),
|
||||
UserAlias.first_name.ilike(f"%{query}%"),
|
||||
UserAlias.last_name.ilike(f"%{query}%"),
|
||||
UserAlias.title.ilike(f"%{query}%"),
|
||||
InventoryAlias.name.ilike(f"%{query}%"),
|
||||
InventoryAlias.serial.ilike(f"%{query}%"),
|
||||
InventoryAlias.barcode.ilike(f"%{query}%")
|
||||
))
|
||||
worklog_results = worklog_query.all()
|
||||
|
||||
|
||||
results = {
|
||||
'inventory': {
|
||||
'results': inventory_query,
|
||||
'headers': inventory_headers,
|
||||
'results': inventory_query,
|
||||
'headers': inventory_headers,
|
||||
'rows': [{"id": item.id, "cells": [fn(item) for fn in inventory_headers.values()]} for item in inventory_results]
|
||||
},
|
||||
'users': {
|
||||
'results': user_query,
|
||||
'headers': user_headers,
|
||||
'results': user_query,
|
||||
'headers': user_headers,
|
||||
'rows': [{"id": user.id, "cells": [fn(user) for fn in user_headers.values()]} for user in user_results]
|
||||
},
|
||||
'worklog': {
|
||||
'results': worklog_query,
|
||||
'headers': worklog_headers,
|
||||
'results': worklog_query,
|
||||
'headers': worklog_headers,
|
||||
'rows': [{"id": log.id, "cells": [fn(log) for fn in worklog_headers.values()]} for log in worklog_results]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,32 @@ def user(id):
|
|||
worklog_rows=[{"id": log.id, "cells": [fn(log) for fn in filtered_worklog_headers.values()]} for log in worklog]
|
||||
)
|
||||
|
||||
@main.route("/user/<id>/org")
|
||||
def user_org(id):
|
||||
user = eager_load_user_relationships(db.session.query(User).filter(User.id == id)).first()
|
||||
if not user:
|
||||
return render_template('error.html', title='User Not Found', message=f'User with ID {id} not found.')
|
||||
|
||||
current_user = user
|
||||
org_chart = []
|
||||
while current_user:
|
||||
subordinates = (
|
||||
eager_load_user_relationships(
|
||||
db.session.query(User).filter(User.supervisor_id == current_user.id)
|
||||
).all()
|
||||
)
|
||||
org_chart.insert(0, {
|
||||
"user": current_user,
|
||||
"subordinates": [subordinate for subordinate in subordinates if subordinate.active and subordinate.staff]
|
||||
})
|
||||
current_user = current_user.supervisor
|
||||
|
||||
return render_template(
|
||||
"user_org.html",
|
||||
user=user,
|
||||
org_chart=org_chart
|
||||
)
|
||||
|
||||
@main.route("/user/new", methods=["GET"])
|
||||
def new_user():
|
||||
rooms = eager_load_room_relationships(db.session.query(Room)).all()
|
||||
|
|
@ -116,6 +142,7 @@ def update_user(id):
|
|||
user.active = bool(data.get("active", user.active))
|
||||
user.last_name = data.get("last_name", user.last_name)
|
||||
user.first_name = data.get("first_name", user.first_name)
|
||||
user.title = data.get("title", user.title)
|
||||
user.location_id = data.get("location_id", user.location_id)
|
||||
user.supervisor_id = data.get("supervisor_id", user.supervisor_id)
|
||||
|
||||
|
|
@ -155,6 +182,7 @@ def get_user_csv():
|
|||
"active",
|
||||
"last_name",
|
||||
"first_name",
|
||||
"title",
|
||||
"location",
|
||||
"supervisor"
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue