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_headers=active_worklog_headers,
|
||||||
active_worklog_rows=active_worklog_rows,
|
active_worklog_rows=active_worklog_rows,
|
||||||
labels=labels,
|
labels=labels,
|
||||||
datasets=datasets
|
datasets=datasets,
|
||||||
|
endpoint='index'
|
||||||
)
|
)
|
||||||
|
|
||||||
def link(text, endpoint, **values):
|
def link(text, endpoint, **values):
|
||||||
|
@ -204,7 +205,8 @@ def list_inventory():
|
||||||
breadcrumb=[{'label': 'Inventory', 'url': url_for('main.inventory_index')}],
|
breadcrumb=[{'label': 'Inventory', 'url': url_for('main.inventory_index')}],
|
||||||
header=inventory_headers,
|
header=inventory_headers,
|
||||||
rows=[{"id": item.id, "cells": [row_fn(item) for row_fn in inventory_headers.values()]} for item in inventory],
|
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")
|
@main.route("/inventory/index")
|
||||||
|
@ -229,7 +231,13 @@ def inventory_index():
|
||||||
elif category:
|
elif category:
|
||||||
return f"Dude, why {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'])
|
@main.route("/inventory_item/<int:id>", methods=['GET', 'POST'])
|
||||||
def inventory_item(id):
|
def inventory_item(id):
|
||||||
|
@ -247,32 +255,22 @@ def inventory_item(id):
|
||||||
title = f"Inventory Record - {item.identifier}"
|
title = f"Inventory Record - {item.identifier}"
|
||||||
else:
|
else:
|
||||||
title = "Inventory Record - Not Found"
|
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,
|
return render_template("inventory.html", title=title, item=item,
|
||||||
brands=brands, users=users, rooms=rooms,
|
brands=brands, users=users, rooms=rooms,
|
||||||
worklog=worklog,
|
worklog=worklog,
|
||||||
worklog_headers=filtered_worklog_headers,
|
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],
|
||||||
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")
|
@main.route("/users")
|
||||||
def list_users():
|
def list_users():
|
||||||
query = eager_load_user_relationships(db.session.query(User)).order_by(User.last_name, User.first_name)
|
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,
|
header = user_headers,
|
||||||
rows = [{"id": user.id, "cells": [fn(user) for fn in user_headers.values()]} for user in users],
|
rows = [{"id": user.id, "cells": [fn(user) for fn in user_headers.values()]} for user in users],
|
||||||
title = "Users",
|
title = "Users",
|
||||||
entry_route = 'user'
|
entry_route = 'user',
|
||||||
|
endpoint='list_users'
|
||||||
)
|
)
|
||||||
|
|
||||||
@main.route("/user/<int:id>")
|
@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_query = eager_load_worklog_relationships(db.session.query(WorkLog)).filter(WorkLog.contact_id == id)
|
||||||
worklog = worklog_query.order_by(WorkLog.start_time.desc()).all()
|
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?']}
|
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(
|
return render_template(
|
||||||
"user.html",
|
"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,
|
user=user, users=users, rooms=rooms, assets=inventory,
|
||||||
inventory_headers=filtered_inventory_headers,
|
inventory_headers=filtered_inventory_headers,
|
||||||
inventory_rows=[{"id": item.id, "cells": [fn(item) for fn in filtered_inventory_headers.values()]} for item in inventory],
|
inventory_rows=[{"id": item.id, "cells": [fn(item) for fn in filtered_inventory_headers.values()]} for item in inventory],
|
||||||
worklog=worklog,
|
worklog=worklog,
|
||||||
worklog_headers=filtered_worklog_headers,
|
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")
|
@main.route("/worklog")
|
||||||
|
@ -325,7 +339,8 @@ def list_worklog(page=1):
|
||||||
header=worklog_headers,
|
header=worklog_headers,
|
||||||
rows=[{"id": log.id, "cells": [fn(log) for fn in worklog_headers.values()]} for log in query.all()],
|
rows=[{"id": log.id, "cells": [fn(log) for fn in worklog_headers.values()]} for log in query.all()],
|
||||||
title="Work Log",
|
title="Work Log",
|
||||||
entry_route='worklog_entry'
|
entry_route='worklog_entry',
|
||||||
|
endpoint='list_worklog'
|
||||||
)
|
)
|
||||||
|
|
||||||
@main.route("/worklog/<int:id>")
|
@main.route("/worklog/<int:id>")
|
||||||
|
@ -335,7 +350,29 @@ def worklog_entry(id):
|
||||||
users = eager_load_user_relationships(user_query).all()
|
users = eager_load_user_relationships(user_query).all()
|
||||||
item_query = db.session.query(Inventory)
|
item_query = db.session.query(Inventory)
|
||||||
items = eager_load_inventory_relationships(item_query).all()
|
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")
|
@main.route("/search")
|
||||||
def 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'])
|
@main.route('/settings', methods=['GET', 'POST'])
|
||||||
def settings():
|
def settings():
|
||||||
|
@ -467,5 +504,6 @@ def settings():
|
||||||
sections=[s.serialize() for s in sections],
|
sections=[s.serialize() for s in sections],
|
||||||
functions=[f.serialize() for f in functions],
|
functions=[f.serialize() for f in functions],
|
||||||
rooms=[r.serialize() for r in rooms],
|
rooms=[r.serialize() for r in rooms],
|
||||||
|
endpoint='settings'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -12,12 +12,10 @@ title=title,
|
||||||
submit_button=True) }}
|
submit_button=True) }}
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<form method="POST" action="{{ url_for('main.inventory_item', id=item.id) }}">
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<label for="timestamp" class="form-label">Date Entered</label>
|
<label for="timestamp" class="form-label">Date Entered</label>
|
||||||
<input type="date" class="form-control" name="timestamp"
|
<input type="date" class="form-control" name="timestamp" value="{{ item.timestamp.date().isoformat() }}">
|
||||||
value="{{ item.timestamp.date().isoformat() }}">
|
|
||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<label for="identifier" class="form-label">Identifier</label>
|
<label for="identifier" class="form-label">Identifier</label>
|
||||||
|
@ -99,14 +97,15 @@ submit_button=True) }}
|
||||||
<option>-</option>
|
<option>-</option>
|
||||||
{% for condition in ["Working", "Deployed", "Partially Inoperable", "Inoperable", "Unverified",
|
{% for condition in ["Working", "Deployed", "Partially Inoperable", "Inoperable", "Unverified",
|
||||||
"Removed", "Disposed"] %}
|
"Removed", "Disposed"] %}
|
||||||
<option value="{{ condition }}"{% if item.condition == condition %} selected{% endif %}>{{ condition }}</option>
|
<option value="{{ condition }}" {% if item.condition==condition %} selected{% endif %}>{{ condition }}
|
||||||
|
</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-2 d-flex align-items-center justify-content-center" style="margin-top: 1.9rem;">
|
<div class="col-2 d-flex align-items-center justify-content-center" style="margin-top: 1.9rem;">
|
||||||
<div class="form-check mb-0">
|
<div class="form-check mb-0">
|
||||||
<input type="checkbox" class="form-check-input" id="shared" name="shared" {% if item.shared
|
<input type="checkbox" class="form-check-input" id="shared" name="shared" {% if item.shared %}checked{%
|
||||||
%}checked{% endif %}>
|
endif %}>
|
||||||
<label for="shared" class="form-check-label">Shared?</label>
|
<label for="shared" class="form-check-label">Shared?</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -124,6 +123,5 @@ submit_button=True) }}
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -53,7 +53,7 @@
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
<main class="container-flex m-5">
|
<main class="container-flex m-5">
|
||||||
<form method="POST" id="settingsForm" action="{{ url_for('main.settings') }}">
|
<form method="POST" id="settingsForm" action="{{ url_for('main.' + endpoint, **(endpoint_args or {})) }}">
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
<input type="hidden" name="formState" id="formStateField">
|
<input type="hidden" name="formState" id="formStateField">
|
||||||
</form>
|
</form>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue