Skip to content

Commit 399aee7

Browse files
committed
add model_name config in APIJSON_TABLES; add func_change_get_params to apijson-table; add other 2 type in apijson-table add modal; add query parameter in _query_array
1 parent eea55fd commit 399aee7

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

uliweb_apijson/apijson/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@
22

33
def get_apijson_tables(role="UNKNOWN"):
44
from uliweb import settings
5-
apijson_tables = dict(settings.APIJSON_TABLES.iteritems())
5+
6+
s = settings.APIJSON_TABLES
7+
if s:
8+
apijson_tables = dict(s.iteritems())
9+
else:
10+
return {}
611
for n in apijson_tables:
712
c = apijson_tables[n]
813
editable = c["editable"]
14+
model_name = c.get("model_name") or n
915
if editable=="auto":
1016
editable = False
11-
POST = settings.APIJSON_MODELS[n]["POST"]
17+
POST = settings.APIJSON_MODELS[model_name]["POST"]
1218
if POST:
1319
roles = POST["roles"]
1420
if roles:

uliweb_apijson/apijson/templates/vue/inc_apijson_table.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<script>
22
Vue.component('apijson-table', {
33
delimiters: ['{', '}'],
4-
props: ["table_name","config"],
4+
props: ["table_name","config","func_change_get_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>
77
<i-table stripe border :columns="tcolumns" :data="tlist" @on-sort-change="table_on_sort_change"></i-table>
88
<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>
99
<modal v-model="modal_add" title="Add" @on-ok="real_add">
1010
<i-form @submit.native.prevent :label-width="80">
1111
<form-item v-for="item in add_items" :key="item.key" :label="item.title">
12+
<i-input v-if="item.type=='input'" v-model="item.value"></i-input>
13+
<checkbox v-if="item.type=='checkbox'" v-model="item.value"></checkbox>
1214
<i-input v-if="item.type=='textarea'" v-model="item.value" type="textarea" :autosize="{minRows: 2,maxRows: 5}"></i-input>
1315
</form-item>
1416
</i-form>
@@ -117,6 +119,9 @@
117119
"[]":arr_params,
118120
"total@":"/[]/total"
119121
}
122+
if (thisp.func_change_get_params!=null) {
123+
params = thisp.func_change_get_params(params)
124+
}
120125
$.ajax({
121126
type: "POST",
122127
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",

uliweb_apijson/apijson/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,10 @@ def _get_array(self,key):
195195
if not owner_filtered:
196196
return json({"code":400,"msg":"'%s' cannot filter with owner"%(modelname)})
197197

198+
for n in model_param:
199+
if n[0]!="@" and hasattr(model,n):
200+
q = q.filter(getattr(model.c,n)==model_param[n])
201+
198202
if query_type in [1,2]:
199203
self.vars["/%s/total"%(key)] = q.count()
200204

0 commit comments

Comments
 (0)