From 41da60e987dffcb03bc3ab8a8667abb6732aea00 Mon Sep 17 00:00:00 2001 From: Chunlin Zhang Date: Wed, 30 Jan 2019 16:36:52 +0800 Subject: [PATCH 1/6] safe get from dict in get_apijson_tables --- uliweb_apijson/apijson/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uliweb_apijson/apijson/__init__.py b/uliweb_apijson/apijson/__init__.py index 8cdfa5f..f275ba1 100644 --- a/uliweb_apijson/apijson/__init__.py +++ b/uliweb_apijson/apijson/__init__.py @@ -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: From 2ab1138549367a2bafd8329868efb35555004e67 Mon Sep 17 00:00:00 2001 From: Chunlin Zhang Date: Wed, 30 Jan 2019 18:11:20 +0800 Subject: [PATCH 2/6] add Spin when loading; fix wrong current_page when page size change --- uliweb_apijson/apijson/templates/vue/inc_apijson_table.html | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html b/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html index 19818cc..149ef6d 100644 --- a/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html +++ b/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html @@ -4,6 +4,7 @@ props: ["table_name","config","func_init","func_change_params"], template: `
Add

+ @@ -37,6 +38,7 @@ data: function(){ var thisp = this return { + loading: false, modal_view: false, viewedit_items: [], @@ -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) { @@ -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() } }, From 4c0adad3ac7e2ccc2f076f3779b89b2f3dbd19da Mon Sep 17 00:00:00 2001 From: Chunlin Zhang Date: Thu, 31 Jan 2019 11:30:34 +0800 Subject: [PATCH 3/6] add like query support in _get_array --- uliweb_apijson/apijson/views.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/uliweb_apijson/apijson/views.py b/uliweb_apijson/apijson/views.py index 34294e2..7418ac4 100644 --- a/uliweb_apijson/apijson/views.py +++ b/uliweb_apijson/apijson/views.py @@ -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() From 8574c8051c1e18a679871856770d47dd1b23ca14 Mon Sep 17 00:00:00 2001 From: Chunlin Zhang Date: Thu, 31 Jan 2019 11:46:18 +0800 Subject: [PATCH 4/6] add page_size config support in apijson-table --- uliweb_apijson/apijson/templates/vue/inc_apijson_table.html | 3 +++ 1 file changed, 3 insertions(+) diff --git a/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html b/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html index 149ef6d..1b05c24 100644 --- a/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html +++ b/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html @@ -357,6 +357,9 @@ if (this.config.add_fields!=null) { this.add_items = this.config_add_fields } + if (this.config.page_size!=null) { + this.query_count = this.config.page_size + } } if (this.func_init!=null) { this.func_init(this) From 1ee86be62fc7e70da2500379a0a91305ef6f5053 Mon Sep 17 00:00:00 2001 From: Chunlin Zhang Date: Thu, 31 Jan 2019 12:01:27 +0800 Subject: [PATCH 5/6] page-size -> default_page_size --- uliweb_apijson/apijson/templates/vue/inc_apijson_table.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html b/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html index 1b05c24..b5f5e8d 100644 --- a/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html +++ b/uliweb_apijson/apijson/templates/vue/inc_apijson_table.html @@ -357,8 +357,8 @@ if (this.config.add_fields!=null) { this.add_items = this.config_add_fields } - if (this.config.page_size!=null) { - this.query_count = this.config.page_size + if (this.config.default_page_size!=null) { + this.query_count = this.config.default_page_size } } if (this.func_init!=null) { From 0e18d89e79277496307faee7be487c4a6a37a4bc Mon Sep 17 00:00:00 2001 From: Chunlin Zhang Date: Thu, 31 Jan 2019 13:36:25 +0800 Subject: [PATCH 6/6] add like query example in demo --- demo/apps/apijson_demo/views.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/demo/apps/apijson_demo/views.py b/demo/apps/apijson_demo/views.py index 1e89e1c..7c59d8e 100644 --- a/demo/apps/apijson_demo/views.py +++ b/demo/apps/apijson_demo/views.py @@ -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%" + } + } }''', }, ]