Fixing render_form's sins.
This commit is contained in:
parent
27431a7150
commit
7f6cbf66fb
7 changed files with 211 additions and 11 deletions
|
|
@ -8,6 +8,7 @@ from crudkit.integrations.flask import init_app
|
|||
|
||||
from .routes.index import init_index_routes
|
||||
from .routes.listing import init_listing_routes
|
||||
from .routes.entry import init_entry_routes
|
||||
|
||||
def create_app(config_cls=crudkit.DevConfig) -> Flask:
|
||||
app = Flask(__name__)
|
||||
|
|
@ -44,6 +45,7 @@ def create_app(config_cls=crudkit.DevConfig) -> Flask:
|
|||
|
||||
init_index_routes(app)
|
||||
init_listing_routes(app)
|
||||
init_entry_routes(app)
|
||||
|
||||
@app.teardown_appcontext
|
||||
def _remove_session(_exc):
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Room(Base, CRUDMixin):
|
|||
is_deleted: Mapped[Boolean] = mapped_column(Boolean, nullable=False, default=False, server_default=sql.false())
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Room(id={self.id}, name={repr(self.name)}, area={repr(self.area.name)}, function={repr(self.room_function.description)})>"
|
||||
return f"<Room id={self.id} name={self.name!r} area_id={self.area_id!r} function_id={self.function_id!r}>"
|
||||
|
||||
@hybrid_property
|
||||
def label(self):
|
||||
|
|
|
|||
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)
|
||||
5
inventory/templates/entry.html
Normal file
5
inventory/templates/entry.html
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block main %}
|
||||
{{ form | safe }}
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue