bugfix
This commit is contained in:
parent
68da1a1aea
commit
93d52f1a51
11
dataui/bricks_parser.py
Normal file
11
dataui/bricks_parser.py
Normal 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'
|
||||||
|
|
@ -166,7 +166,7 @@ async def main():
|
|||||||
s = await crud_render(cmd, jsonfile)
|
s = await crud_render(cmd, jsonfile)
|
||||||
print(s)
|
print(s)
|
||||||
|
|
||||||
class BricksCRUDProcessor(TemplateProcessor):
|
class BaseCRUDProcessor(TemplateProcessor):
|
||||||
"""
|
"""
|
||||||
accept json data from frontend with such attributes:
|
accept json data from frontend with such attributes:
|
||||||
{
|
{
|
||||||
@ -176,7 +176,7 @@ class BricksCRUDProcessor(TemplateProcessor):
|
|||||||
"""
|
"""
|
||||||
@classmethod
|
@classmethod
|
||||||
def isMe(self, name):
|
def isMe(self, name):
|
||||||
return name == 'bricks_crud'
|
return name == 'none_crud'
|
||||||
|
|
||||||
async def run_pyscript(self, txt, request):
|
async def run_pyscript(self, txt, request):
|
||||||
lines = [ '\t' + l for l in txt.split('\n') ]
|
lines = [ '\t' + l for l in txt.split('\n') ]
|
||||||
@ -187,6 +187,10 @@ class BricksCRUDProcessor(TemplateProcessor):
|
|||||||
del lenv['request']
|
del lenv['request']
|
||||||
return await f(request, **lenv)
|
return await f(request, **lenv)
|
||||||
|
|
||||||
|
def create_parser(self):
|
||||||
|
cp = CrudParser(frontend='bricks')
|
||||||
|
return cp
|
||||||
|
|
||||||
async def path_call(self, request, params={}):
|
async def path_call(self, request, params={}):
|
||||||
self.run_ns.update(params)
|
self.run_ns.update(params)
|
||||||
params_kw = await self.run_ns.get('request2ns')()
|
params_kw = await self.run_ns.get('request2ns')()
|
||||||
@ -197,7 +201,8 @@ class BricksCRUDProcessor(TemplateProcessor):
|
|||||||
dic['request'] = request
|
dic['request'] = request
|
||||||
baseurl = request.path.split('/')[-1]
|
baseurl = request.path.split('/')[-1]
|
||||||
dic['baseurl'] = baseurl
|
dic['baseurl'] = baseurl
|
||||||
cp = CrudParser(frontend='bricks')
|
# cp = CrudParser(frontend='bricks')
|
||||||
|
cp = self.create_parser()
|
||||||
s = await cp.render(cmd, dic)
|
s = await cp.render(cmd, dic)
|
||||||
if cmd in [ "select", "insert", "update", "delete" ]:
|
if cmd in [ "select", "insert", "update", "delete" ]:
|
||||||
s = await self.run_pyscript(s, request)
|
s = await self.run_pyscript(s, request)
|
||||||
|
11
dataui/kivyblocks_parser.py
Normal file
11
dataui/kivyblocks_parser.py
Normal 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'
|
||||||
|
|
25
dataui/tmpl/kivyblocks/crud_add.tmpl
Normal file
25
dataui/tmpl/kivyblocks/crud_add.tmpl
Normal 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 %}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
17
dataui/tmpl/kivyblocks/crud_browser.tmpl
Normal file
17
dataui/tmpl/kivyblocks/crud_browser.tmpl
Normal 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)}}
|
||||||
|
}
|
||||||
|
}
|
57
dataui/tmpl/kivyblocks/crud_choose.tmpl
Normal file
57
dataui/tmpl/kivyblocks/crud_choose.tmpl
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
9
dataui/tmpl/kivyblocks/crud_delete.tmpl
Normal file
9
dataui/tmpl/kivyblocks/crud_delete.tmpl
Normal 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
|
||||||
|
}
|
||||||
|
}
|
25
dataui/tmpl/kivyblocks/crud_edit.tmpl
Normal file
25
dataui/tmpl/kivyblocks/crud_edit.tmpl
Normal 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 %}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
27
dataui/tmpl/kivyblocks/crud_filter.tmpl
Normal file
27
dataui/tmpl/kivyblocks/crud_filter.tmpl
Normal 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);"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
12
dataui/tmpl/kivyblocks/crud_insert.tmpl
Normal file
12
dataui/tmpl/kivyblocks/crud_insert.tmpl
Normal 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
|
||||||
|
}
|
||||||
|
}
|
16
dataui/tmpl/kivyblocks/crud_remove.tmpl
Normal file
16
dataui/tmpl/kivyblocks/crud_remove.tmpl
Normal 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()"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
9
dataui/tmpl/kivyblocks/crud_select.tmpl
Normal file
9
dataui/tmpl/kivyblocks/crud_select.tmpl
Normal 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
|
7
dataui/tmpl/kivyblocks/crud_update.tmpl
Normal file
7
dataui/tmpl/kivyblocks/crud_update.tmpl
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
db = DBPools()
|
||||||
|
async with db.sqlorContext('{{database}}') as sor:
|
||||||
|
await sor.U(params_kw)
|
||||||
|
return {
|
||||||
|
"state":"ok",
|
||||||
|
"data"{}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user