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'
|
||||
)
|
||||
|
||||
|
|
|
@ -12,118 +12,116 @@ title=title,
|
|||
submit_button=True) }}
|
||||
|
||||
<div class="container">
|
||||
<form method="POST" action="{{ url_for('main.inventory_item', id=item.id) }}">
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<label for="timestamp" class="form-label">Date Entered</label>
|
||||
<input type="date" class="form-control" name="timestamp"
|
||||
value="{{ item.timestamp.date().isoformat() }}">
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label for="identifier" class="form-label">Identifier</label>
|
||||
<input type="text" class="form-control-plaintext" value="{{ item.identifier }}" readonly>
|
||||
<div class="row">
|
||||
<div class="col-6">
|
||||
<label for="timestamp" class="form-label">Date Entered</label>
|
||||
<input type="date" class="form-control" name="timestamp" value="{{ item.timestamp.date().isoformat() }}">
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label for="identifier" class="form-label">Identifier</label>
|
||||
<input type="text" class="form-control-plaintext" value="{{ item.identifier }}" readonly>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<label for="inventory_name" class="form-label">Inventory #</label>
|
||||
<input type="text" class="form-control" name="inventory_name" placeholder="-"
|
||||
value="{{ item.inventory_name or '' }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="serial" class="form-label">Serial #</label>
|
||||
<input type="text" class="form-control" name="serial" placeholder="-"
|
||||
value="{{ item.serial if item.serial else '' }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="barcode" class="form-label">Bar Code #</label>
|
||||
<input type="text" class="form-control" name="barcode" placeholder="-"
|
||||
value="{{ item.barcode if item.barcode else '' }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<label for="brand" class="form-label">Brand</label>
|
||||
<select class="form-select" id="brand" name="brand">
|
||||
<option>-</option>
|
||||
{% for brand in brands %}
|
||||
<option value="{{ brand.id }}" {% if brand.id==item.brand_id %} selected{% endif %}>{{ brand.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="model" class="form-label">Model</label>
|
||||
<input type="text" class="form-control" name="model" placeholder="-" value="{{ item.model }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="type" class="form-label">Category</label>
|
||||
<select name="type" id="type" class="form-select">
|
||||
<option>-</option>
|
||||
{% for t in types %}
|
||||
<option value="{{ t.id }}" {% if t.id==item.type_id %} selected{% endif %}>{{ t.description }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<label for="owner" class="form-label">
|
||||
Contact
|
||||
{% if item.owner %}
|
||||
{{ links.entry_link('user', item.owner_id) }}
|
||||
{% endif %}
|
||||
</label>
|
||||
<select class="form-select" id="userList">
|
||||
<option>-</option>
|
||||
{% for user in users %}
|
||||
<option value="{{ user.id }}" {% if user.id==item.owner_id %} selected{% endif %}>{{ user.full_name
|
||||
}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="location" class="form-label">Location</label>
|
||||
<select class="form-select" id="room">
|
||||
<option>-</option>
|
||||
{% for room in rooms %}
|
||||
<option value="{{ room.id }}" {% if room.id==item.location_id %} selected{% endif %}>{{
|
||||
room.full_name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label for="condition" class="form-label">Condition</label>
|
||||
<select name="condition" id="condition" class="form-select">
|
||||
<option>-</option>
|
||||
{% for condition in ["Working", "Deployed", "Partially Inoperable", "Inoperable", "Unverified",
|
||||
"Removed", "Disposed"] %}
|
||||
<option value="{{ condition }}" {% if item.condition==condition %} selected{% endif %}>{{ condition }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-2 d-flex align-items-center justify-content-center" style="margin-top: 1.9rem;">
|
||||
<div class="form-check mb-0">
|
||||
<input type="checkbox" class="form-check-input" id="shared" name="shared" {% if item.shared %}checked{%
|
||||
endif %}>
|
||||
<label for="shared" class="form-check-label">Shared?</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<label for="inventory_name" class="form-label">Inventory #</label>
|
||||
<input type="text" class="form-control" name="inventory_name" placeholder="-"
|
||||
value="{{ item.inventory_name or '' }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="serial" class="form-label">Serial #</label>
|
||||
<input type="text" class="form-control" name="serial" placeholder="-"
|
||||
value="{{ item.serial if item.serial else '' }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="barcode" class="form-label">Bar Code #</label>
|
||||
<input type="text" class="form-control" name="barcode" placeholder="-"
|
||||
value="{{ item.barcode if item.barcode else '' }}">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label for="notes" class="form-label">Notes & Comments</label>
|
||||
<textarea name="notes" id="notes" class="form-control"
|
||||
rows="10">{{ item.notes if item.notes else '' }}</textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<label for="brand" class="form-label">Brand</label>
|
||||
<select class="form-select" id="brand" name="brand">
|
||||
<option>-</option>
|
||||
{% for brand in brands %}
|
||||
<option value="{{ brand.id }}" {% if brand.id==item.brand_id %} selected{% endif %}>{{ brand.name }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="model" class="form-label">Model</label>
|
||||
<input type="text" class="form-control" name="model" placeholder="-" value="{{ item.model }}">
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="type" class="form-label">Category</label>
|
||||
<select name="type" id="type" class="form-select">
|
||||
<option>-</option>
|
||||
{% for t in types %}
|
||||
<option value="{{ t.id }}" {% if t.id==item.type_id %} selected{% endif %}>{{ t.description }}
|
||||
</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% if worklog %}
|
||||
<div class="col">
|
||||
{{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog',
|
||||
entry_route='worklog_entry', title='Work Log') }}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-4">
|
||||
<label for="owner" class="form-label">
|
||||
Contact
|
||||
{% if item.owner %}
|
||||
{{ links.entry_link('user', item.owner_id) }}
|
||||
{% endif %}
|
||||
</label>
|
||||
<select class="form-select" id="userList">
|
||||
<option>-</option>
|
||||
{% for user in users %}
|
||||
<option value="{{ user.id }}" {% if user.id==item.owner_id %} selected{% endif %}>{{ user.full_name
|
||||
}}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-4">
|
||||
<label for="location" class="form-label">Location</label>
|
||||
<select class="form-select" id="room">
|
||||
<option>-</option>
|
||||
{% for room in rooms %}
|
||||
<option value="{{ room.id }}" {% if room.id==item.location_id %} selected{% endif %}>{{
|
||||
room.full_name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-2">
|
||||
<label for="condition" class="form-label">Condition</label>
|
||||
<select name="condition" id="condition" class="form-select">
|
||||
<option>-</option>
|
||||
{% for condition in ["Working", "Deployed", "Partially Inoperable", "Inoperable", "Unverified",
|
||||
"Removed", "Disposed"] %}
|
||||
<option value="{{ condition }}"{% if item.condition == condition %} selected{% endif %}>{{ condition }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-2 d-flex align-items-center justify-content-center" style="margin-top: 1.9rem;">
|
||||
<div class="form-check mb-0">
|
||||
<input type="checkbox" class="form-check-input" id="shared" name="shared" {% if item.shared
|
||||
%}checked{% endif %}>
|
||||
<label for="shared" class="form-check-label">Shared?</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<label for="notes" class="form-label">Notes & Comments</label>
|
||||
<textarea name="notes" id="notes" class="form-control"
|
||||
rows="10">{{ item.notes if item.notes else '' }}</textarea>
|
||||
</div>
|
||||
{% if worklog %}
|
||||
<div class="col">
|
||||
{{ tables.render_table(headers=worklog_headers, rows=worklog_rows, id='worklog',
|
||||
entry_route='worklog_entry', title='Work Log') }}
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
</form>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -53,7 +53,7 @@
|
|||
</div>
|
||||
</nav>
|
||||
<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 %}
|
||||
<input type="hidden" name="formState" id="formStateField">
|
||||
</form>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue