Fixing render_form's sins.
This commit is contained in:
parent
27431a7150
commit
7f6cbf66fb
7 changed files with 211 additions and 11 deletions
33
inventory/routes/entry.py
Normal file
33
inventory/routes/entry.py
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
from flask import Blueprint, render_template, abort, request, jsonify
|
||||
|
||||
import crudkit
|
||||
|
||||
from crudkit.api._cursor import decode_cursor, encode_cursor
|
||||
from crudkit.ui.fragments import render_form
|
||||
|
||||
bp_entry = Blueprint("entry", __name__)
|
||||
|
||||
def init_entry_routes(app):
|
||||
|
||||
@bp_entry.get("/entry/<model>/<int:id>")
|
||||
def entry(model: str, id: int):
|
||||
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", "supervisor"]})
|
||||
if obj is None:
|
||||
abort(404)
|
||||
|
||||
form = render_form(
|
||||
cls,
|
||||
obj.as_dict(),
|
||||
crudkit.crud.get_service(cls).session,
|
||||
label_specs={
|
||||
"supervisor": "{first_name} {last_name}",
|
||||
"location": "{name} - {room_function.description}"
|
||||
},
|
||||
)
|
||||
|
||||
return render_template("entry.html", form=form)
|
||||
|
||||
app.register_blueprint(bp_entry)
|
||||
Loading…
Add table
Add a link
Reference in a new issue