diff --git a/inventory/models/user.py b/inventory/models/user.py index 21bc2b6..6ecc432 100644 --- a/inventory/models/user.py +++ b/inventory/models/user.py @@ -51,6 +51,8 @@ class User(Base, CRUDMixin): @hybrid_property def label(self): out = f"{self.first_name} {self.last_name}" + if self.title: + out = out + f" ({self.title})" return out @label.expression @@ -66,4 +68,9 @@ class User(Base, CRUDMixin): space = case((have_first & have_last, literal(" ")), else_=literal("")) - return func.concat(first, space, last) + title_part = case( + (func.length(sql_trim(title, backend)) > 0, func.concat(" (", title, ")")), + else_=literal("") + ) + + return func.concat(first, space, last, title_part) diff --git a/inventory/routes/entry.py b/inventory/routes/entry.py index f434c0f..7800fdd 100644 --- a/inventory/routes/entry.py +++ b/inventory/routes/entry.py @@ -4,7 +4,7 @@ from sqlalchemy.inspection import inspect from typing import Any, Dict, List, Tuple, Callable, Optional import crudkit -from crudkit.ui.fragments import render_form, render_table, register_template_globals +from crudkit.ui.fragments import render_form, register_template_globals from crudkit.core import normalize_payload bp_entry = Blueprint("entry", __name__) @@ -15,7 +15,10 @@ def _fields_for_model(model: str): layout = [] if model == "inventory": - fields = [] + fields = ["label", "name", "serial", "barcode", "brand", "model", + "device_type", "owner", "location", "condition", "image", + "notes", "work_logs.start_time", "work_logs.work_item.label", + "work_logs.contact.label", "work_logs.complete"] fields_spec = [ {"name": "label", "type": "display", "label": "", "row": "label", "attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}}, @@ -55,8 +58,7 @@ def _fields_for_model(model: str): "wrap": {"class": "h-100 w-100"}}, {"name": "notes", "type": "template", "label": "Notes", "row": "notes", "wrap": {"class": "col"}, "template": "inventory_note.html"}, - {"name": "work_logs", "type": "template", "template_ctx": {}, "row": "notes", "wrap": {"class": "col"}, - "template": "inventory_logs.html"}, + {"name": "work_logs", "type": "template", "row": "notes", "wrap": {"class": "col"}, "template": "inventory_logs.html"}, ] layout = [ {"name": "label", "order": 5, "attrs": {"class": "row align-items-center"}}, @@ -185,22 +187,6 @@ def init_entry_routes(app): ScopedSession = current_app.extensions["crudkit"]["Session"] - if model == "inventory": - log_cls = crudkit.crud.get_model("worklog") - log_svc = crudkit.crud.get_service(log_cls) - logs = log_svc.list({ - "work_item_id__eq": id, - "fields": "id,contact.label,complete,created_at,updated_at", - }) - fields_spec[13]["template_ctx"]["table"] = render_table(logs, [ - {"field": "id", "label": "ID"}, - {"field": "contact.label", "label": "Contact", - "link": {"endpoint": "entry.entry", "params": {"id": "{contact.id}", "model": "user"}}}, - {"field": "created_at", "label": "Created", "format": "datetime"}, - {"field": "updated_at", "label": "Updated", "format": "datetime"}, - {"field": "complete", "format": "yesno"}, - ], opts={"object_class": "worklog"}) - form = render_form( cls, obj.as_dict(), diff --git a/inventory/templates/inventory_logs.html b/inventory/templates/inventory_logs.html index 5222e1d..00f54f1 100644 --- a/inventory/templates/inventory_logs.html +++ b/inventory/templates/inventory_logs.html @@ -1,2 +1,8 @@ -{{ field['template_ctx']['table'] | safe }} \ No newline at end of file +

+ {{ field }} +

+

+ {{ field['template_ctx']['values']['work_logs'] }} +

+{% include "table.html" %} \ No newline at end of file