Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4a323a5

Browse files
authored
Merge pull request#9 from zhangchunlin/master
add tables demo
2 parents4bfb641 +1ffbf9b commit4a323a5

File tree

12 files changed

+153
-11
lines changed

12 files changed

+153
-11
lines changed

‎demo/apps/apijson_demo/settings.ini

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ moment = 'apijson_demo.models.Moment'
66
[APIJSON_MODELS]
77
moment = {
88
"user_id_field" :"user_id",
9-
"GET" : {"roles" : ["OWNER","LOGIN"] },
10-
"HEAD" : {"roles" : ["OWNER","LOGIN"] },
11-
"POST" : {"roles" : ["OWNER"] },
12-
"PUT" : {"roles" : ["OWNER"] },
13-
"DELETE" : {"roles" : ["OWNER"] },
9+
"GET" : {"roles" : ["OWNER","LOGIN","ADMIN"] },
10+
"HEAD" : {"roles" : ["OWNER","LOGIN","ADMIN"] },
11+
"POST" : {"roles" : ["OWNER","ADMIN"] },
12+
"PUT" : {"roles" : ["OWNER","ADMIN"] },
13+
"DELETE" : {"roles" : ["OWNER","ADMIN"] },
1414
}
1515
comment = {
1616
"user_id_field" :"user_id",
17-
"GET" : {"roles" : ["OWNER","LOGIN"] },
18-
"HEAD" : {"roles" : ["OWNER","LOGIN"] },
19-
"POST" : {"roles" : ["OWNER"] },
20-
"PUT" : {"roles" : ["OWNER"] },
21-
"DELETE" : {"roles" : ["OWNER"] },
17+
"GET" : {"roles" : ["OWNER","LOGIN","ADMIN"] },
18+
"HEAD" : {"roles" : ["OWNER","LOGIN","ADMIN"] },
19+
"POST" : {"roles" : ["OWNER","ADMIN"] },
20+
"PUT" : {"roles" : ["OWNER","ADMIN"] },
21+
"DELETE" : {"roles" : ["OWNER","ADMIN"] },
2222
}
2323

2424
[APIJSON_REQUESTS]

‎demo/apps/settings.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ INSTALLED_APPS = [
1919
'uliweb_comui',
2020
'uliweb_apijson.apijson',
2121
'apijson_demo',
22+
'tables',
2223
]
2324

2425
[MENUS]
2526
MAINMENU = {
2627
'subs':[
2728
{'name':'apijson','link':'/','title':u'APIJSON Demo'},
29+
{'name':'tables','link':'/tables','title':u'APIJSON tables'},
2830
]
2931
}
3032

‎demo/apps/tables/README.md

Whitespace-only changes.

‎demo/apps/tables/__init__.py

Whitespace-only changes.

‎demo/apps/tables/static/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store static files.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{extend "site/layout0.html"}}
2+
3+
{{block title}}uliweb-apijson demo{{end title}}
4+
5+
{{block mainmenu}}
6+
{{<<mainmenu('tables')}}
7+
{{end mainmenu}}
8+
9+
{{block sidemenu}}{{end sidemenu}}
10+
11+
{{block header_custom_menu}}{{end header_custom_menu}}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{{extend "Tables/layout.html"}}
2+
3+
{{block content_main}}
4+
{{use "ui.vue"}}
5+
{{use "ui.iview"}}
6+
{{include "vue/inc_apijson_table.html"}}
7+
{{if role!="ADMIN":}}
8+
<divclass="alert alert-warning"role="alert">You should<aclass="btn btn-primary btn-sm"href="{{=url_for('uliweb_apps.login.views.login')}}"role="button">login</a> with user<strong>admin</strong> to view all the tables</div>
9+
{{pass #if}}
10+
<divid="app">
11+
<tabsv-model:value="tab_current"type="card">
12+
<tab-panev-for="item in tabs":key="item":label="item":name="item">
13+
<apijson-table:table_name="item"></apijson-table>
14+
</tab-pane>
15+
</tabs>
16+
</div>
17+
18+
<script>
19+
varvm=newVue({
20+
el:'#app',
21+
delimiters:['{','}'],
22+
data:{
23+
tab_current:null,
24+
tabs:{{=table_keys_json}}
25+
}
26+
})
27+
</script>
28+
{{end content_main}}

‎demo/apps/tables/templates/readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This directory is used to store template files.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<script>
2+
Vue.component('apijson-table',{
3+
delimiters:['{','}'],
4+
props:["table_name"],
5+
template:`<div>
6+
<i-table stripe border :columns="tcolumns" :data="tlist" @on-sort-change="table_on_sort_change"></i-table>
7+
<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>
8+
</div>`,
9+
data:function(){
10+
return{
11+
tcolumns:[
12+
{title:'#',key:'id'}
13+
],
14+
tcolumns_init:false,
15+
tlist:[],
16+
query_count:10,
17+
current_page:1,
18+
total:0,
19+
sort_key:"id",
20+
sort_order:"-"
21+
}
22+
},
23+
methods:{
24+
update_list:function(){
25+
varthisp=this
26+
vararr_params={
27+
"@count":thisp.query_count,
28+
"@page":thisp.current_page-1,
29+
"@query":2
30+
}
31+
arr_params[this.table_name]={
32+
"@order":thisp.sort_key+thisp.sort_order,
33+
"@role":"{{=role}}"
34+
}
35+
varparams={
36+
"[]":arr_params,
37+
"total@":"/[]/total"
38+
}
39+
$.ajax({
40+
type:"POST",
41+
url:"{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",
42+
contentType:'application/json',
43+
data:JSON.stringify(params),
44+
success:function(data){
45+
if(data.code==200){
46+
vararr=data["[]"]
47+
if(!thisp.tcolumns_init){
48+
if(arr.length>0){
49+
varitem=arr[0]
50+
for(varkinitem){
51+
if(k!="id"){
52+
thisp.tcolumns.push({title:k,key:k})
53+
}
54+
}
55+
thisp.tcolumns_init=true
56+
}
57+
}
58+
thisp.tlist=arr
59+
thisp.total=data.total
60+
}
61+
}
62+
})
63+
},
64+
table_on_sort_change:function(){
65+
66+
},
67+
page_on_change:function(data){
68+
this.update_list()
69+
},
70+
page_on_page_size_change:function(data){
71+
this.query_count=data
72+
this.current_page=0
73+
this.update_list()
74+
}
75+
},
76+
mounted:function(){
77+
this.update_list()
78+
}
79+
})
80+
</script>

‎demo/apps/tables/views.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#coding=utf-8
2+
fromuliwebimportexpose,functions
3+
fromjsonimportdumps
4+
5+
@expose('/tables')
6+
classTables(object):
7+
@expose('')
8+
deflist(self):
9+
table_keys=settings.APIJSON_MODELS.keys()
10+
ifrequest.userandfunctions.has_role(request.user,"ADMIN"):
11+
role="ADMIN"
12+
elifrequest.user:
13+
role="LOGIN"
14+
else:
15+
role="UNKNOWN"
16+
return {
17+
"table_keys_json":dumps(table_keys),
18+
"role":role
19+
}

‎demo/doc/imgs/demo_screenshot.png

-14.5 KB
Loading

‎uliweb_apijson/apijson/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _get_array(self,key):
123123
ifquery_page:
124124
#@page begin from 0
125125
try:
126-
query_page=int(params[n])
126+
query_page=int(query_page)
127127
exceptValueErrorase:
128128
log.error("bad param in '%s': '%s'"%(n,params))
129129
returnjson({"code":400,"msg":"@page should be an int, now '%s'"%(params[n])})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp