Skip to content

Commit 0d8237c

Browse files
authored
Merge pull request #18 from zhangchunlin/master
同步
2 parents a057ca0 + 0e18d89 commit 0d8237c

4 files changed

Lines changed: 37 additions & 5 deletions

File tree

demo/apps/apijson_demo/views.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ def index():
6262
}
6363
},
6464
"total@":"/moment[]/total"
65+
}''',
66+
},
67+
{
68+
"label":"Array query: like",
69+
"value":'''{
70+
"[]":{
71+
"@count":4,
72+
"@page":0,
73+
"user":{
74+
"@column":"id,username,nickname,email",
75+
"@order":"id-",
76+
"@role":"ADMIN",
77+
"username$":"%user%"
78+
}
79+
}
6580
}''',
6681
},
6782
]

uliweb_apijson/apijson/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ def get_apijson_tables(role="UNKNOWN"):
1010
return {}
1111
for n in apijson_tables:
1212
c = apijson_tables[n]
13-
editable = c["editable"]
13+
editable = c.get("editable",False)
1414
_model_name = c.get("@model_name") or n
1515
if editable=="auto":
1616
editable = False
17-
POST = settings.APIJSON_MODELS[_model_name]["POST"]
17+
POST = settings.APIJSON_MODELS.get(_model_name,{}).get("POST")
1818
if POST:
1919
roles = POST["roles"]
2020
if roles:

uliweb_apijson/apijson/templates/vue/inc_apijson_table.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
props: ["table_name","config","func_init","func_change_params"],
55
template: `<div>
66
<div v-if="config_editable && config_add_fields!=null"><i-button type="primary" @click="add">Add</i-button> <br><br> </div>
7+
<Spin size="large" fix v-if="loading"></Spin>
78
<i-table stripe border :columns="tcolumns" :data="tlist" @on-sort-change="table_on_sort_change"></i-table>
89
<page :total="total" :page-size="query_count" :current.sync="current_page" :page-size-opts="[10, 20, 50, 100]" show-sizer @on-change="page_on_change" @on-page-size-change="page_on_page_size_change"></page>
910
<modal v-model="modal_add" title="Add">
@@ -37,6 +38,7 @@
3738
data: function(){
3839
var thisp = this
3940
return {
41+
loading: false,
4042
modal_view: false,
4143
viewedit_items: [],
4244

@@ -125,12 +127,14 @@
125127
if (thisp.func_change_params!=null) {
126128
params = thisp.func_change_params("apijson_get",params)
127129
}
130+
thisp.loading = true
128131
$.ajax({
129132
type: "POST",
130133
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",
131134
contentType: 'application/json',
132135
data: JSON.stringify(params),
133136
success: function (data) {
137+
thisp.loading = false
134138
if (data.code==200) {
135139
var arr = data["[]"]
136140
if (!thisp.tcolumns_init) {
@@ -340,7 +344,7 @@
340344
},
341345
page_on_page_size_change: function(data) {
342346
this.query_count = data
343-
this.current_page = 0
347+
this.current_page = 1
344348
this.update_list()
345349
}
346350
},
@@ -353,6 +357,9 @@
353357
if (this.config.add_fields!=null) {
354358
this.add_items = this.config_add_fields
355359
}
360+
if (this.config.default_page_size!=null) {
361+
this.query_count = this.config.default_page_size
362+
}
356363
}
357364
if (this.func_init!=null) {
358365
this.func_init(this)

uliweb_apijson/apijson/views.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,18 @@ def _get_array(self,key):
196196
return json({"code":400,"msg":"'%s' cannot filter with owner"%(modelname)})
197197

198198
for n in model_param:
199-
if n[0]!="@" and hasattr(model,n):
200-
q = q.filter(getattr(model.c,n)==model_param[n])
199+
if n[0]!="@":
200+
if n[-1]=="$":
201+
name = n[:-1]
202+
if hasattr(model,name):
203+
q = q.filter(getattr(model.c,name).like(model_param[n]))
204+
elif n[-1]=="}" and n[-2]=="{":
205+
name = n[:-2]
206+
if hasattr(model,name):
207+
# TODO
208+
pass
209+
elif hasattr(model,n):
210+
q = q.filter(getattr(model.c,n)==model_param[n])
201211

202212
if query_type in [1,2]:
203213
self.vars["/%s/total"%(key)] = q.count()

0 commit comments

Comments
 (0)