Compare commits
2 commits
57104824a1
...
5a1f978aa2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5a1f978aa2 | ||
|
|
29dc740725 |
3 changed files with 22 additions and 21 deletions
|
|
@ -51,8 +51,6 @@ 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
|
||||
|
|
@ -68,9 +66,4 @@ class User(Base, CRUDMixin):
|
|||
|
||||
space = case((have_first & have_last, literal(" ")), else_=literal(""))
|
||||
|
||||
title_part = case(
|
||||
(func.length(sql_trim(title, backend)) > 0, func.concat(" (", title, ")")),
|
||||
else_=literal("")
|
||||
)
|
||||
|
||||
return func.concat(first, space, last, title_part)
|
||||
return func.concat(first, space, last)
|
||||
|
|
|
|||
|
|
@ -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, register_template_globals
|
||||
from crudkit.ui.fragments import render_form, render_table, register_template_globals
|
||||
from crudkit.core import normalize_payload
|
||||
|
||||
bp_entry = Blueprint("entry", __name__)
|
||||
|
|
@ -15,10 +15,7 @@ def _fields_for_model(model: str):
|
|||
layout = []
|
||||
|
||||
if model == "inventory":
|
||||
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 = []
|
||||
fields_spec = [
|
||||
{"name": "label", "type": "display", "label": "", "row": "label",
|
||||
"attrs": {"class": "display-6 mb-3"}, "wrap": {"class": "col"}},
|
||||
|
|
@ -58,7 +55,8 @@ 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", "row": "notes", "wrap": {"class": "col"}, "template": "inventory_logs.html"},
|
||||
{"name": "work_logs", "type": "template", "template_ctx": {}, "row": "notes", "wrap": {"class": "col"},
|
||||
"template": "inventory_logs.html"},
|
||||
]
|
||||
layout = [
|
||||
{"name": "label", "order": 5, "attrs": {"class": "row align-items-center"}},
|
||||
|
|
@ -187,6 +185,22 @@ 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(),
|
||||
|
|
|
|||
|
|
@ -1,8 +1,2 @@
|
|||
<label class="form-label">Work Logs</label>
|
||||
<p>
|
||||
{{ field }}
|
||||
</p>
|
||||
<p>
|
||||
{{ field['template_ctx']['values']['work_logs'] }}
|
||||
</p>
|
||||
{% include "table.html" %}
|
||||
{{ field['template_ctx']['table'] | safe }}
|
||||
Loading…
Add table
Add a link
Reference in a new issue