WIP on getting work_log support on inventory page.

This commit is contained in:
Yaro Kasear 2025-10-03 16:26:04 -05:00
parent 7935b5b57d
commit 57104824a1
5 changed files with 117 additions and 68 deletions

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
from crudkit.ui.fragments import render_form, register_template_globals
from crudkit.core import normalize_payload
bp_entry = Blueprint("entry", __name__)
@ -17,7 +17,8 @@ def _fields_for_model(model: str):
if model == "inventory":
fields = ["label", "name", "serial", "barcode", "brand", "model",
"device_type", "owner", "location", "condition", "image",
"notes", "work_logs"]
"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"}},
@ -57,6 +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", "row": "notes", "wrap": {"class": "col"}, "template": "inventory_logs.html"},
]
layout = [
{"name": "label", "order": 5, "attrs": {"class": "row align-items-center"}},
@ -103,6 +105,7 @@ def _fields_for_model(model: str):
]
elif model == "worklog":
# tell the service to eager-load precisely what the template needs
fields = [
"id",
"contact.label",
@ -165,6 +168,8 @@ def _apply_worklog_updates(worklog, updates, delete_ids):
note_svc.delete(uid, actor="bulk_child_delete", commit=False)
def init_entry_routes(app):
# Make helpers available in all templates
register_template_globals(app)
@bp_entry.get("/entry/<model>/<int:id>")
def entry(model: str, id: int):

View file

@ -3,11 +3,14 @@ from flask import Blueprint, render_template, abort, request
import crudkit
from crudkit.api._cursor import decode_cursor, encode_cursor
from crudkit.ui.fragments import render_table
from crudkit.ui.fragments import render_table, register_template_globals
bp_listing = Blueprint("listing", __name__)
def init_listing_routes(app):
# Make helpers available in all templates
register_template_globals(app)
@bp_listing.get("/listing/<model>")
def show_list(model):
if model.lower() not in {"inventory", "user", "worklog"}: