Lots of form code done!

This commit is contained in:
Conrad Nelson 2025-09-18 16:03:12 -05:00
parent 25589a79d3
commit 2ae96e5c80
6 changed files with 400 additions and 60 deletions

View file

@ -14,26 +14,79 @@ def init_entry_routes(app):
cls = crudkit.crud.get_model(model)
if cls is None:
abort(404)
obj = crudkit.crud.get_service(cls).get(id, {"fields": ["first_name", "last_name", "title", "active", "staff", "location", "location_id"]})
if model not in ["inventory", "worklog", "user"]:
abort(404)
fields = {}
fields_spec = []
layout = []
if model == "inventory":
fields["fields"] = ["label", "name", "barcode", "serial"]
fields_spec = [
{"name": "label", "label": "", "row": "label", "wrap": {"class": "col"}},
{"name": "name", "label": "Name", "row": "identification", "wrap": {"class": "col"}},
{"name": "barcode", "label": "Bar Code #", "row": "identification", "wrap": {"class": "col"}},
{"name": "serial", "label": "Serial #", "row": "identification", "wrap": {"class": "col"}},
]
layout = [
{"name": "label", "order": 10, "attrs": {"class": "row"}},
{"name": "identification", "order": 20, "attrs": {"class": "row"}},
]
elif model.lower() == 'user':
fields["fields"] = ["label", "first_name", "last_name", "title", "active", "staff", "location", "supervisor"]
fields_spec = [
{"name": "label", "row": "label", "label": "User Record",
"label_attrs": {"class": "display-6"}, "type": "display",
"attrs": {"class": "display-4 mb-3"}, "wrap": {"class": "text-center"}},
{"name": "last_name", "label": "Last Name", "label_attrs": {"class": "form-label"},
"attrs": {"placeholder": "Doe", "class": "form-control"},
"row": "name", "wrap": {"class": "col-2"}},
{"name": "first_name", "label": "First Name", "label_attrs": {"class": "form-label"},
"attrs": {"placeholder": "John", "class": "form-control"},
"row": "name", "wrap": {"class": "col-2"}},
{"name": "title", "label": "Title", "label_attrs": {"class": "form-label"},
"attrs": {"placeholder": "President of the Universe", "class": "form-control"},
"row": "name", "wrap": {"class": "col-2"}},
{"name": "supervisor", "label": "Supervisor", "label_attrs": {"class": "form-label"},
"label_spec": "{first_name} {last_name}", "row": "details", "wrap": {"class": "col-3"},
"attrs": {"class": "form-control"}},
{"name": "location", "label": "Room", "label_attrs": {"class": "form-label"},
"label_spec": "{name} - {room_function.description}",
"row": "details", "wrap": {"class": "col-3"}, "attrs": {"class": "form-control"}},
{"name": "active", "label": "Active", "label_attrs": {"class": "form-check-label"},
"row": "checkboxes", "attrs": {"class": "form-check-input"}, "wrap": {"class": "form-check"}},
{"name": "staff", "label": "Staff Member", "label_attrs": {"class": "form-check-label"},
"row": "checkboxes", "attrs": {"class": "form-check-input"}, "wrap": {"class": "form-check"}},
]
layout = [
{"name": "label", "order": 0},
{"name": "name", "order": 10, "attrs": {"class": "row mb-3"}},
{"name": "details", "order": 20, "attrs": {"class": "row"}},
{"name": "checkboxes", "order": 30, "parent": "name", "attrs": {"class": "col d-flex flex-column justify-content-end"}}
]
elif model == "worklog":
pass
obj = crudkit.crud.get_service(cls).get(id, fields)
if obj is None:
abort(404)
fields_spec = [
{"name": "last_name", "label": "Last Name", "attrs": {"placeholder": "Doe"}},
{"name": "first_name", "label": "First Name", "attrs": {"placeholder": "John"}},
{"name": "title", "label": "Title", "attrs": {"placeholder": "President of the Universe"}},
{"name": "active", "label": "Active"},
{"name": "staff", "label": "Staff Member"},
{"name": "location", "label": "Room", "label_spec": "{name} - {room_function.description}"}
]
form = render_form(
cls,
obj.as_dict(),
crudkit.crud.get_service(cls).session,
instance=obj,
fields_spec=fields_spec
fields_spec=fields_spec,
layout=layout,
submit_attrs={"class": "btn btn-primary"}
)
return render_template("entry.html", form=form)
app.register_blueprint(bp_entry)