diff --git a/crudkit/ui/fragments.py b/crudkit/ui/fragments.py index c1e771b..c443d8b 100644 --- a/crudkit/ui/fragments.py +++ b/crudkit/ui/fragments.py @@ -1189,5 +1189,6 @@ def render_form( values=values_map, render_field=render_field, submit_attrs=submit_attrs, - submit_label=submit_label + submit_label=submit_label, + model_name=model_cls.__name__ ) diff --git a/crudkit/ui/templates/form.html b/crudkit/ui/templates/form.html index 03fab61..9a23d51 100644 --- a/crudkit/ui/templates/form.html +++ b/crudkit/ui/templates/form.html @@ -1,4 +1,4 @@ -
+ {% macro render_row(row) %} {% if row.fields or row.children or row.legend %} diff --git a/inventory/routes/entry.py b/inventory/routes/entry.py index dec7553..34b4fc5 100644 --- a/inventory/routes/entry.py +++ b/inventory/routes/entry.py @@ -96,7 +96,9 @@ def init_entry_routes(app): fields["fields"] = ["id", "contact", "work_item", "start_time", "end_time", "complete"] fields_spec = [ {"name": "id", "label": "", "type": "display", "label_spec": "Work Item #{id}", - "attrs": {"class": "display-6 mb-3"}, "row": "label"}, + "attrs": {"class": "display-6 mb-3"}, "row": "label", "wrap": {"class": "col"}}, + {"name": "submit", "label": "", "row": "label", "type": "template", "template": "submit_button.html", + "wrap": {"class": "col text-end me-2"}, "attrs": {"data-model": model}}, {"name": "contact", "row": "ownership", "wrap": {"class": "col"}, "label": "Contact", "label_spec": "{label}", "attrs": {"class": "form-control"}, "label_attrs": {"class": "form-label"}}, {"name": "work_item", "row": "ownership", "wrap": {"class": "col"}, "label": "Work Item", @@ -111,7 +113,7 @@ def init_entry_routes(app): "type": "template", "template": "update_list.html"}, ] layout = [ - {"name": "label", "order": 0}, + {"name": "label", "order": 0, "attrs": {"class": "row align-items-center"}}, {"name": "ownership", "order": 10, "attrs": {"class": "row mb-2"}}, {"name": "timestamps", "order": 20, "attrs": {"class": "row d-flex align-items-center"}}, {"name": "updates", "order": 30, "attrs": {"class": "row"}}, @@ -132,7 +134,6 @@ def init_entry_routes(app): updates_cls.is_deleted == False) .order_by(updates_cls.timestamp.asc())) all_updates = updates_q.all() - print(all_updates) for f in fields_spec: if f.get("name") == "updates" and f.get("type") == "template": @@ -141,8 +142,6 @@ def init_entry_routes(app): f["template_ctx"] = ctx break - print(fields_spec) - form = render_form( cls, obj.as_dict(), @@ -150,13 +149,34 @@ def init_entry_routes(app): instance=obj, fields_spec=fields_spec, layout=layout, - submit_attrs={"class": "btn btn-primary mt-3"}, + submit_attrs={"class": "d-none", "disabled": True}, ) - # sanity log - u = getattr(obj, "updates", None) - print("WORKLOG UPDATES loaded? ", - "None" if u is None else f"len={len(list(u))} ids={[n.id for n in list(u)]}") return render_template("entry.html", form=form) + @bp_entry.post("/entry//") + def update_entry(model, id): + try: + if model not in ["inventory", "user", "worklog"]: + raise TypeError("Invalid model.") + payload = request.get_json() + cls = crudkit.crud.get_model(model) + + if model == "inventory": + pass + elif model == "user": + pass + elif model == "worklog": + pass + else: + raise TypeError("Invalid model.") + + service = crudkit.crud.get_service(cls) + item = service.get(id) + print(item.as_dict(), payload) + + return {"status": "success", "payload": payload} + except Exception as e: + return {"status": "failure", "error": str(e)} + app.register_blueprint(bp_entry) diff --git a/inventory/routes/reports.py b/inventory/routes/reports.py index e914002..d12bff9 100644 --- a/inventory/routes/reports.py +++ b/inventory/routes/reports.py @@ -89,8 +89,6 @@ def inventory_spares(): ) rows = session.execute(stmt).all() - print(rows) - items = [] for dev, dep, avail in rows: dep = int(dep or 0) diff --git a/inventory/templates/base.html b/inventory/templates/base.html index a7bfadd..8af3f31 100644 --- a/inventory/templates/base.html +++ b/inventory/templates/base.html @@ -5,7 +5,8 @@ {% block title %}{{ title if title else "Inventory Manager" }}{% endblock %} - +