Starting work on listings.
This commit is contained in:
parent
64e8d6871f
commit
d045a1a05f
5 changed files with 42 additions and 17 deletions
|
|
@ -1,13 +1,34 @@
|
|||
from flask import Blueprint, render_template
|
||||
from flask import Blueprint, render_template, abort
|
||||
|
||||
from ..db import get_session
|
||||
import crudkit
|
||||
|
||||
from crudkit.ui.fragments import render_table
|
||||
|
||||
bp_listing = Blueprint("listing", __name__)
|
||||
|
||||
def init_listing_routes(app):
|
||||
@bp_listing.get("/listing/<model>")
|
||||
def show_list(model):
|
||||
session = get_session()
|
||||
return render_template("listing.html", model=model)
|
||||
cls = crudkit.crud.get_model(model)
|
||||
if cls is None:
|
||||
abort(404)
|
||||
|
||||
spec = {}
|
||||
if model.lower() == 'inventory':
|
||||
spec = {"fields": [
|
||||
"label",
|
||||
"name",
|
||||
"barcode",
|
||||
"serial",
|
||||
"device_type.description"
|
||||
]}
|
||||
spec["limit"] = 0
|
||||
|
||||
service = crudkit.crud.get_service(cls)
|
||||
rows = service.list(spec)
|
||||
|
||||
table = render_table(rows, opts={"object_class": model})
|
||||
|
||||
return render_template("listing.html", model=model, table=table)
|
||||
|
||||
app.register_blueprint(bp_listing)
|
||||
Loading…
Add table
Add a link
Reference in a new issue