This commit is contained in:
yumoqing 2023-12-24 12:01:35 +08:00
parent 68da1a1aea
commit 93d52f1a51
13 changed files with 234 additions and 3 deletions

11
dataui/bricks_parser.py Normal file
View File

@ -0,0 +1,11 @@
from .crud_parser import BaseCRUDProcessor
class BricksCRUDProcessor(TemplateProcessor):
def create_parser(self):
cp = CrudParser(frontend='bricks')
return cp
@classmethod
def isMe(self, name):
return name == 'bricks_crud'

View File

@ -166,7 +166,7 @@ async def main():
s = await crud_render(cmd, jsonfile)
print(s)
class BricksCRUDProcessor(TemplateProcessor):
class BaseCRUDProcessor(TemplateProcessor):
"""
accept json data from frontend with such attributes:
{
@ -176,7 +176,7 @@ class BricksCRUDProcessor(TemplateProcessor):
"""
@classmethod
def isMe(self, name):
return name == 'bricks_crud'
return name == 'none_crud'
async def run_pyscript(self, txt, request):
lines = [ '\t' + l for l in txt.split('\n') ]
@ -187,6 +187,10 @@ class BricksCRUDProcessor(TemplateProcessor):
del lenv['request']
return await f(request, **lenv)
def create_parser(self):
cp = CrudParser(frontend='bricks')
return cp
async def path_call(self, request, params={}):
self.run_ns.update(params)
params_kw = await self.run_ns.get('request2ns')()
@ -197,7 +201,8 @@ class BricksCRUDProcessor(TemplateProcessor):
dic['request'] = request
baseurl = request.path.split('/')[-1]
dic['baseurl'] = baseurl
cp = CrudParser(frontend='bricks')
# cp = CrudParser(frontend='bricks')
cp = self.create_parser()
s = await cp.render(cmd, dic)
if cmd in [ "select", "insert", "update", "delete" ]:
s = await self.run_pyscript(s, request)

View File

@ -0,0 +1,11 @@
from .crud_parser import BaseCRUDProcessor
class KivyblocksCRUDProcessor(TemplateProcessor):
def create_parser(self):
cp = CrudParser(frontend='kivyblocks')
return cp
@classmethod
def isMe(self, name):
return name == 'kivyblocks_crud'

View File

@ -0,0 +1,25 @@
{
"widgettype":"PopupForm",
"options":{
"submit_url":"{{baseurl}}?command=insert",
"width":"{{width}}",
"height":"{{height}},
"title":"{{title}}",
"description":"{{description}}",
"fields":[
{% for f in fields %}
{
{% if node == 'view' %}
"readonly":true,
{% endif %}
"name":"{{f.name}}",
"label":"{{f.label}}",
"datatype":"{{f.datatype}}",
"uitype":"{{f.uitype}}",
"width":"{{f.width}}"
}
{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}

View File

@ -0,0 +1,17 @@
{
"widgettype":"DataGrid",
"options":{
{% if admin %}
"admin":true,
{% endif %}
{% if lineno %}
"lineno":true,
{% endif %}
{% if check %}
"check":true,
{% endif %}
"dataurl":"{{baseurl}}?command=select",
"title":"{{title}}",
"fields":{{json.dumps(fields)}}
}
}

View File

@ -0,0 +1,57 @@
{
"widgettype":"VBox",
"options":{
"height":"auto",
"width":"100%"
},
"subwidgets":[
{
widgettype":"DataGrid",
"options":{
"check":true,
"dataurl":"{{baseurl}}?command=select",
"title":"{{title}}",
"fields":[
{% for f in fields %}
{
{% if node == 'view' %}
"readonly":true,
{% endif %}
"name":"{{f.name}}",
"label":"{{f.label}}",
"datatype":"{{f.datatype}}",
"uitype":"{{f.uitype}}",
"width":"{{f.width}}"
}
{% if not loop.last %},{% endif %}
{% endfor %}
]
}
},
{
"widgettype":"HBox",
"options":{
"height":"auto",
"width":"100%"
},
"subwidgets":[
{
"widgettype":"Button",
"options":{
"icon":"/imgs/select.png",
"name":"select",
"Label":"Select"
}
},
{
"widgettype":"Button",
"options":{
"icon":"/imgs/discard.png",
"name":"discard",
"Label":"Discard"
}
}
]
}
]
}

View File

@ -0,0 +1,9 @@
db = DBPools()
async with db.sqlorContext('{{database}}') as sor:
await sor.D("{{table}}", params_kw)
return {
"state":"ok",
"data":{
k:id
}
}

View File

@ -0,0 +1,25 @@
{
"widgettype":"ModalForm",
"options":{
"width":"{{width}}",
"height":"{{height}},
"submit_url":"{{baseurl}}?command=update",
"title":"{{title}}",
"description":"{{description}}",
"fields":[
{% for f in fields %}
{
{% if node == 'view' %}
"readonly":true,
{% endif %}
"name":"{{f.name}}",
"label":"{{f.label}}",
"datatype":"{{f.datatype}}",
"uitype":"{{f.uitype}}",
"width":"{{f.width}}"
}
{% if not loop.last %},{% endif %}
{% endfor %}
]
}
}

View File

@ -0,0 +1,27 @@
{
"widgettype":"ModalForm",
"options":{
"fields":[
{% for f in fileds %}
{
"name":"{{f.name}}",
"label":"{{f.title}}",
"uitype":"{{f.uitype",
"uiparams":{{f.uiparanms}}"
}
{% if not loop.last %},{% endif %}
{% endfor %}
]
},
"binds":[
{
"wid":"self",
"event":"submit",
"actiontype":"script",
"target":"{{params_kw.target}}",
"datawidget":"self",
"script":"self.loadData(kwargs);"
}
]
}

View File

@ -0,0 +1,12 @@
db = DBPools()
id = uuid()
async with db.sqlorContext('{{database}}') as sor:
k = info.summary[0].primary[0]
params_kw.update({k:id})
await sor.C("{{table}}", params_kw)
return {
"state":"ok",
"data":{
k:id
}
}

View File

@ -0,0 +1,16 @@
{
"widgettype":"Conform",
"options":{
"title":"Delete record",
"message":"delete record, are you sure?"
},
"binds":[
{
"wid":"self",
"event":"conform",
"actiontype":"script",
"target":"{{params_kw.target}}",
"script":"self.del_row()"
}
]
}

View File

@ -0,0 +1,9 @@
if not params_kw.get('page'):
params_kw['page'] = 1
if not params_kw.get('rows'):
params_kw['rows'] = 80
print('params_kw=', params_kw)
db = DBPools()
async with db.sqlorContext('{{database}}') as sor:
d = await sor.R("{{table}}", params_kw)
return d

View File

@ -0,0 +1,7 @@
db = DBPools()
async with db.sqlorContext('{{database}}') as sor:
await sor.U(params_kw)
return {
"state":"ok",
"data"{}
}