From e260731a42727d7bef530e3f704ad1e5d095dd91 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 12 Jul 2025 21:54:29 +0800 Subject: [PATCH] bugfix --- tmpls.py | 12 ++++++++++++ xls2crud.py | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/tmpls.py b/tmpls.py index a93dcdd..d9f0ba2 100644 --- a/tmpls.py +++ b/tmpls.py @@ -24,9 +24,21 @@ data_browser_tmpl = """ {% endif %} {% if not noedit %} "editable":{ +{% if new_data_url %} + "new_data_url": "{{new_data_url}}", +{% else %} "new_data_url":{%- raw -%}"{{entire_url('add_{%- endraw -%}{{summary[0].name}}{%- raw -%}.dspy')}}",{%- endraw %} +{% endif %} +{% if delete_data_url %} + "delete_data_url": "{{delete_data_url}}", +{% else %} "delete_data_url":{%- raw -%}"{{entire_url('delete_{%- endraw -%}{{summary[0].name}}{%- raw -%}.dspy')}}",{%- endraw %} +{% endif %} +{% if update_data_url %} + "update_data_url": "{{update_data_url}}", +{% else %} "update_data_url":{%- raw -%}"{{entire_url('update_{%- endraw -%}{{summary[0].name}}{%- raw -%}.dspy')}}"{%- endraw %} +{% endif %} }, {% endif %} diff --git a/xls2crud.py b/xls2crud.py index d3180c9..74417a0 100644 --- a/xls2crud.py +++ b/xls2crud.py @@ -41,11 +41,54 @@ def build_subtable(subtable): } } +def subtable2toolbar(desc): + if desc.subtables is None: + return + if desc.toolbar is None: + desc.toolbar = DictObject(**{ + "tools":[] + }) + tools = desc.toolbar.tools + binds = desc.binds or [] + for st in desc.subtables: + tools.append({ + "selected_row": True, + "name": st.subtable, + "icon":"{{entire_url('/imgs/" + st.subtable + ".svg')}}", + "label": st.title + }) + binds.append({ + "wid":"self", + "event":st.subtable, + "actiontype": "urlwidget", + "target":"PopupWindow", + "params_mapping":{ + "mapping":{ + "id": st.field + }, + "need_others": False + }, + "popup_options":{ + "resizable": True, + "height":"70%", + "width":"70%" + }, + "options":{ + "methid":"POST", + "params":{}, + "url":st.url or "{{entire_url('../" + st.subtable + "')}}" + } + }) + + desc.toolbar.tools = tools + desc.binds = binds + def build_crud_ui(crud_data: dict, dbdesc: dict): uidir = crud_data.output_dir tables = [ k for k in dbdesc.keys() ] desc = dbdesc[crud_data.tblname] desc.update(crud_data.params) + subtable2toolbar(desc) binds = desc.binds or [] if desc.relation: desc.checkField = 'has_' + desc.relation.param_field @@ -60,6 +103,7 @@ def build_crud_ui(crud_data: dict, dbdesc: dict): } }) desc.bindsstr = json.dumps(binds, indent=4, ensure_ascii=False) + """ if desc.subtables: if len(desc.subtables) == 1: t = desc.subtables[0] @@ -86,7 +130,7 @@ def build_crud_ui(crud_data: dict, dbdesc: dict): } }) desc.content_view = content_view - + """ desc.update({ "tblname":crud_data.tblname, "dbname":crud_data.dbname