Refactor inventory and layout templates; enhance form handling with dynamic endpoint and argument passing for improved flexibility
This commit is contained in:
parent
be1e56ad93
commit
f2229cdc90
3 changed files with 173 additions and 137 deletions
92
routes.py
92
routes.py
|
@ -152,7 +152,8 @@ def index():
|
|||
active_worklog_headers=active_worklog_headers,
|
||||
active_worklog_rows=active_worklog_rows,
|
||||
labels=labels,
|
||||
datasets=datasets
|
||||
datasets=datasets,
|
||||
endpoint='index'
|
||||
)
|
||||
|
||||
def link(text, endpoint, **values):
|
||||
|
@ -204,7 +205,8 @@ def list_inventory():
|
|||
breadcrumb=[{'label': 'Inventory', 'url': url_for('main.inventory_index')}],
|
||||
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'
|
||||
entry_route = 'inventory_item',
|
||||
endpoint='list_inventory'
|
||||
)
|
||||
|
||||
@main.route("/inventory/index")
|
||||
|
@ -229,7 +231,13 @@ def inventory_index():
|
|||
elif category:
|
||||
return f"Dude, why {category}?"
|
||||
|
||||
return render_template('inventory_index.html', title=f"Inventory ({category.capitalize()} Index)" if category else "Inventory", category=category, listing=listing)
|
||||
return render_template(
|
||||
'inventory_index.html',
|
||||
title=f"Inventory ({category.capitalize()} Index)" if category else "Inventory",
|
||||
category=category,
|
||||
listing=listing,
|
||||
endpoint='inventory_index'
|
||||
)
|
||||
|
||||
@main.route("/inventory_item/<int:id>", methods=['GET', 'POST'])
|
||||
def inventory_item(id):
|
||||
|
@ -247,32 +255,22 @@ def inventory_item(id):
|
|||
title = f"Inventory Record - {item.identifier}"
|
||||
else:
|
||||
title = "Inventory Record - Not Found"
|
||||
return render_template('error.html',
|
||||
title=title,
|
||||
message=f'Inventory item with id {id} not found!',
|
||||
endpoint='inventory_item',
|
||||
endpoint_args={'id': -1})
|
||||
|
||||
return render_template("inventory.html", title=title, item=item,
|
||||
brands=brands, users=users, rooms=rooms,
|
||||
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],
|
||||
types=types
|
||||
types=types,
|
||||
endpoint='inventory_item',
|
||||
endpoint_args={'id': item.id}
|
||||
)
|
||||
|
||||
@main.route("/inventory_item/new", methods=['GET', 'POST'])
|
||||
def new_inventory_item():
|
||||
brands = db.session.query(Brand).all()
|
||||
users = eager_load_user_relationships(db.session.query(User)).all()
|
||||
rooms = eager_load_room_relationships(db.session.query(Room)).all()
|
||||
types = db.session.query(Item).all()
|
||||
|
||||
if request.method == 'POST':
|
||||
# Handle form submission logic here
|
||||
pass
|
||||
# If GET request, render the form for creating a new inventory item
|
||||
if not brands:
|
||||
return render_template("error.html", title="No Brands Found", message="Please add at least one brand before creating an inventory item.")
|
||||
|
||||
return render_template("inventory.html", title="New Inventory Item",
|
||||
brands=brands, users=users, rooms=rooms, types=types)
|
||||
|
||||
@main.route("/users")
|
||||
def list_users():
|
||||
query = eager_load_user_relationships(db.session.query(User)).order_by(User.last_name, User.first_name)
|
||||
|
@ -282,7 +280,8 @@ def list_users():
|
|||
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'
|
||||
entry_route = 'user',
|
||||
endpoint='list_users'
|
||||
)
|
||||
|
||||
@main.route("/user/<int:id>")
|
||||
|
@ -305,15 +304,30 @@ def user(id):
|
|||
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!",
|
||||
endpoint='user',
|
||||
endpoint_args={'id': -1}
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"user.html",
|
||||
title=(f"User Record - {user.full_name}" if user.active else f"User Record - {user.full_name} (Inactive)") if user else "User Record - Record Not Found",
|
||||
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]
|
||||
worklog_rows=[{"id": log.id, "cells": [fn(log) for fn in filtered_worklog_headers.values()]} for log in worklog],
|
||||
endpoint='user',
|
||||
endpoint_args={'id': user.id}
|
||||
)
|
||||
|
||||
@main.route("/worklog")
|
||||
|
@ -325,7 +339,8 @@ def list_worklog(page=1):
|
|||
header=worklog_headers,
|
||||
rows=[{"id": log.id, "cells": [fn(log) for fn in worklog_headers.values()]} for log in query.all()],
|
||||
title="Work Log",
|
||||
entry_route='worklog_entry'
|
||||
entry_route='worklog_entry',
|
||||
endpoint='list_worklog'
|
||||
)
|
||||
|
||||
@main.route("/worklog/<int:id>")
|
||||
|
@ -335,7 +350,29 @@ def worklog_entry(id):
|
|||
users = eager_load_user_relationships(user_query).all()
|
||||
item_query = db.session.query(Inventory)
|
||||
items = eager_load_inventory_relationships(item_query).all()
|
||||
return render_template("worklog.html", title=f"Work Log #{id}", log=log, users=users, items=items, form_fields=worklog_form_fields)
|
||||
|
||||
if log:
|
||||
title = f'Work Log - Entry #{id}'
|
||||
else:
|
||||
title = "Work Log - Entry Not Found"
|
||||
return render_template(
|
||||
'error.html',
|
||||
title=title,
|
||||
message=f"The work log with ID {id} is not found!",
|
||||
endpoint='worklog_entry',
|
||||
endpoint_args={'id': -1}
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"worklog.html",
|
||||
title=title,
|
||||
log=log,
|
||||
users=users,
|
||||
items=items,
|
||||
form_fields=worklog_form_fields,
|
||||
endpoint='worklog_entry',
|
||||
endpoint_args={'id': log.id}
|
||||
)
|
||||
|
||||
@main.route("/search")
|
||||
def search():
|
||||
|
@ -394,7 +431,7 @@ def search():
|
|||
}
|
||||
}
|
||||
|
||||
return render_template('search.html', title=f"Database Search ({query})" if query else "Database Search", results=results, query=query)
|
||||
return render_template('search.html', title=f"Database Search ({query})" if query else "Database Search", results=results, query=query, endpoint='search')
|
||||
|
||||
@main.route('/settings', methods=['GET', 'POST'])
|
||||
def settings():
|
||||
|
@ -467,5 +504,6 @@ def settings():
|
|||
sections=[s.serialize() for s in sections],
|
||||
functions=[f.serialize() for f in functions],
|
||||
rooms=[r.serialize() for r in rooms],
|
||||
endpoint='settings'
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue