Compare commits

..

No commits in common. "5a1f978aa273a01688da224b99ddc7590f38a557" and "57104824a1194ee504ff2661e84e76d98d50e97f" have entirely different histories.

3 changed files with 21 additions and 22 deletions

View file

@ -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)

View file

@ -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(),

View file

@ -1,2 +1,8 @@
<label class="form-label">Work Logs</label>
{{ field['template_ctx']['table'] | safe }}
<p>
{{ field }}
</p>
<p>
{{ field['template_ctx']['values']['work_logs'] }}
</p>
{% include "table.html" %}