Starting work on listings.
This commit is contained in:
parent
64e8d6871f
commit
d045a1a05f
5 changed files with 42 additions and 17 deletions
|
|
@ -1,24 +1,19 @@
|
|||
from __future__ import annotations
|
||||
import os
|
||||
|
||||
from flask import Flask
|
||||
|
||||
from crudkit import ProdConfig
|
||||
from crudkit.api.flask_api import generate_crud_blueprint
|
||||
from crudkit.core.service import CRUDService
|
||||
from crudkit.integration import CRUDKit
|
||||
from crudkit.integrations.flask import init_app
|
||||
import crudkit
|
||||
|
||||
from .config import DevConfig
|
||||
from crudkit.integrations.flask import init_app
|
||||
|
||||
from .routes.index import init_index_routes
|
||||
from .routes.listing import init_listing_routes
|
||||
|
||||
def create_app(config_cls=DevConfig) -> Flask:
|
||||
def create_app(config_cls=crudkit.DevConfig) -> Flask:
|
||||
app = Flask(__name__)
|
||||
|
||||
runtime = init_app(app, config=ProdConfig)
|
||||
crud = CRUDKit(app, runtime)
|
||||
runtime = init_app(app, config=crudkit.ProdConfig)
|
||||
crudkit.init_crud(app)
|
||||
print(f"Effective DB URL: {str(runtime.engine.url)}")
|
||||
|
||||
from . import models as _models
|
||||
|
|
@ -32,7 +27,7 @@ def create_app(config_cls=DevConfig) -> Flask:
|
|||
|
||||
session = Session
|
||||
|
||||
crud.register_many([
|
||||
crudkit.crud.register_many([
|
||||
_models.Area,
|
||||
_models.Brand,
|
||||
_models.DeviceType,
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
<table class="table table-light table-striped table-hover table-bordered border-tertiary">
|
||||
<table class="table table-light table-striped table-hover table-bordered border-tertiary text-nowrap overflow-x-auto">
|
||||
<thead>
|
||||
<tr>
|
||||
{% for col in columns %}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block main %}
|
||||
Feelin' fine.
|
||||
{{ table | safe }}
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue