Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions demo/apps/apijson_demo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ def index():
}
},
"total@":"/moment[]/total"
}''',
},
{
"label":"Array query: like",
"value":'''{
"[]":{
"@count":4,
"@page":0,
"user":{
"@column":"id,username,nickname,email",
"@order":"id-",
"@role":"ADMIN",
"username$":"%user%"
}
}
}''',
},
]
Expand Down
4 changes: 2 additions & 2 deletions uliweb_apijson/apijson/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def get_apijson_tables(role="UNKNOWN"):
return {}
for n in apijson_tables:
c = apijson_tables[n]
editable = c["editable"]
editable = c.get("editable",False)
_model_name = c.get("@model_name") or n
if editable=="auto":
editable = False
POST = settings.APIJSON_MODELS[_model_name]["POST"]
POST = settings.APIJSON_MODELS.get(_model_name,{}).get("POST")
if POST:
roles = POST["roles"]
if roles:
Expand Down
9 changes: 8 additions & 1 deletion uliweb_apijson/apijson/templates/vue/inc_apijson_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
props: ["table_name","config","func_init","func_change_params"],
template: `<div>
<div v-if="config_editable && config_add_fields!=null"><i-button type="primary" @click="add">Add</i-button> <br><br> </div>
<Spin size="large" fix v-if="loading"></Spin>
<i-table stripe border :columns="tcolumns" :data="tlist" @on-sort-change="table_on_sort_change"></i-table>
<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>
<modal v-model="modal_add" title="Add">
Expand Down Expand Up @@ -37,6 +38,7 @@
data: function(){
var thisp = this
return {
loading: false,
modal_view: false,
viewedit_items: [],

Expand Down Expand Up @@ -125,12 +127,14 @@
if (thisp.func_change_params!=null) {
params = thisp.func_change_params("apijson_get",params)
}
thisp.loading = true
$.ajax({
type: "POST",
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",
contentType: 'application/json',
data: JSON.stringify(params),
success: function (data) {
thisp.loading = false
if (data.code==200) {
var arr = data["[]"]
if (!thisp.tcolumns_init) {
Expand Down Expand Up @@ -340,7 +344,7 @@
},
page_on_page_size_change: function(data) {
this.query_count = data
this.current_page = 0
this.current_page = 1
this.update_list()
}
},
Expand All @@ -353,6 +357,9 @@
if (this.config.add_fields!=null) {
this.add_items = this.config_add_fields
}
if (this.config.default_page_size!=null) {
this.query_count = this.config.default_page_size
}
}
if (this.func_init!=null) {
this.func_init(this)
Expand Down
14 changes: 12 additions & 2 deletions uliweb_apijson/apijson/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,18 @@ def _get_array(self,key):
return json({"code":400,"msg":"'%s' cannot filter with owner"%(modelname)})

for n in model_param:
if n[0]!="@" and hasattr(model,n):
q = q.filter(getattr(model.c,n)==model_param[n])
if n[0]!="@":
if n[-1]=="$":
name = n[:-1]
if hasattr(model,name):
q = q.filter(getattr(model.c,name).like(model_param[n]))
elif n[-1]=="}" and n[-2]=="{":
name = n[:-2]
if hasattr(model,name):
# TODO
pass
elif hasattr(model,n):
q = q.filter(getattr(model.c,n)==model_param[n])

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