This commit is contained in:
yumoqing 2025-07-12 21:54:29 +08:00
parent f6522e744b
commit e260731a42
2 changed files with 57 additions and 1 deletions

View File

@ -24,9 +24,21 @@ data_browser_tmpl = """
{% endif %} {% endif %}
{% if not noedit %} {% if not noedit %}
"editable":{ "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 %} "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 %} "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 %} "update_data_url":{%- raw -%}"{{entire_url('update_{%- endraw -%}{{summary[0].name}}{%- raw -%}.dspy')}}"{%- endraw %}
{% endif %}
}, },
{% endif %} {% endif %}

View File

@ -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): def build_crud_ui(crud_data: dict, dbdesc: dict):
uidir = crud_data.output_dir uidir = crud_data.output_dir
tables = [ k for k in dbdesc.keys() ] tables = [ k for k in dbdesc.keys() ]
desc = dbdesc[crud_data.tblname] desc = dbdesc[crud_data.tblname]
desc.update(crud_data.params) desc.update(crud_data.params)
subtable2toolbar(desc)
binds = desc.binds or [] binds = desc.binds or []
if desc.relation: if desc.relation:
desc.checkField = 'has_' + desc.relation.param_field 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) desc.bindsstr = json.dumps(binds, indent=4, ensure_ascii=False)
"""
if desc.subtables: if desc.subtables:
if len(desc.subtables) == 1: if len(desc.subtables) == 1:
t = desc.subtables[0] t = desc.subtables[0]
@ -86,7 +130,7 @@ def build_crud_ui(crud_data: dict, dbdesc: dict):
} }
}) })
desc.content_view = content_view desc.content_view = content_view
"""
desc.update({ desc.update({
"tblname":crud_data.tblname, "tblname":crud_data.tblname,
"dbname":crud_data.dbname "dbname":crud_data.dbname