Skip to content

Commit 83d9413

Browse files
committed
demo: add user info and login/logout button, add request_post demo type
1 parent d7ab2b2 commit 83d9413

File tree

6 files changed

+69
-15
lines changed

6 files changed

+69
-15
lines changed

demo/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist
88
_git
99
data
1010
database.db
11+
sessions

demo/apps/apijson_demo/templates/index.html

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,46 @@
55
{{use "ui.iview"}}
66

77
<div id="app">
8-
98
<tabs v-model:value="tab_current" type="card" :animated="false">
109
<tab-pane label="apijson get" name="tab_get"></tab-pane>
1110
<tab-pane label="apijson post" name="tab_post"></tab-pane>
1211
<tab-pane label="apijson put" name="tab_put"></tab-pane>
1312
</tabs>
13+
<Row>
14+
<i-col span="3"><div align="center">login user</div></i-col>
15+
<i-col span="8"><i-input value="{{=user_info}}" readonly/></i-col>
16+
{{if request.user:}}
17+
<i-col span="1"><div align="center"><i-button type="warning" size="large" @click="logout">Logout</i-button></div></i-col>
18+
{{else:}}
19+
<i-col span="1"><div align="center"><i-button type="primary" size="large" @click="login">Login</i-button></div></i-col>
20+
{{pass}}
21+
</Row>
1422
<Row v-if="tab_current==='tab_get'">
15-
<i-col span="3"><div align="center">POST URL</div></i-col>
23+
<i-col span="3"><div align="center">HTTP POST URL</div></i-col>
1624
<i-col span="8"><i-input value="/apijson/get" readonly/></i-col>
1725
</Row>
1826
<Row v-if="tab_current==='tab_get'">
19-
<i-col span="3"><div align="center">demo request data list</div></i-col>
27+
<i-col span="3"><div align="center"><strong>apijson get</strong> request examples</div></i-col>
2028
<i-col span="8">
2129
<i-select v-model="request_data">
22-
<i-option v-for="item in request_data_list" :value="item.value" :key="item.value">{ item.label }</i-option>
30+
<i-option v-for="item in request_get" :value="item.value" :key="item.value">{ item.label }</i-option>
2331
</i-select>
2432
</i-col>
2533
</Row>
34+
35+
<Row v-if="tab_current==='tab_post'">
36+
<i-col span="3"><div align="center">POST URL</div></i-col>
37+
<i-col span="8"><i-input value="/apijson/post" readonly/></i-col>
38+
</Row>
39+
<Row v-if="tab_current==='tab_post'">
40+
<i-col span="3"><div align="center"><strong>apijson post</strong> request examples</div></i-col>
41+
<i-col span="8">
42+
<i-select v-model="request_data">
43+
<i-option v-for="item in request_post" :value="item.value" :key="item.value">{ item.label }</i-option>
44+
</i-select>
45+
</i-col>
46+
</Row>
47+
2648
<Row>
2749
<i-col span="3"><div align="center">request data</div></i-col>
2850
<i-col span="8"><i-input v-model="request_data" type="textarea" :autosize="{minRows: 3,maxRows: 15}" placeholder="request data" /></i-col>
@@ -38,29 +60,36 @@
3860
el: '#app',
3961
delimiters: ['{', '}'],
4062
data: {
41-
request_data_list : {{=request_data_list_json}},
63+
request_get : {{=request_get_json}},
64+
request_post : {{=request_post_json}},
4265
request_data : "",
4366
can_post : true,
4467
response_data : "",
45-
tab_current : "tab_get"
68+
tab_current : "tab_get",
69+
tab2url : {
70+
"tab_get":"{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",
71+
"tab_post":"{{=url_for('uliweb_apijson.apijson.views.ApiJson.post')}}"
72+
}
4673
},
4774
methods: {
4875
init_default: function(){
49-
vm.request_data = vm.request_data_list[0].value
76+
vm.request_data = vm.request_get[0].value
5077
},
5178
post_request_data: function(){
5279
$.ajax({
5380
type: "POST",
5481
contentType: 'application/json',
55-
url: "{{=url_for('uliweb_apijson.apijson.views.ApiJson.get')}}",
82+
url: vm.tab2url[vm.tab_current],
5683
data: vm.request_data,
5784
success: function (data) {
5885
vm.response_data = JSON.stringify(data,null,2)
5986
vm.can_post = false
6087
}
6188
})
6289

63-
}
90+
},
91+
login: function(){window.location.href="{{=url_for('uliweb_apps.login.views.login')}}"},
92+
logout: function(){window.location.href="{{=url_for('uliweb_apps.login.views.logout')}}"}
6493
},
6594
watch: {
6695
request_data : function(n,o){

demo/apps/apijson_demo/templates/layout_demo.html

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

33
{{block title}}uliweb-apijson demo{{end title}}
44

5-
{{block header_container_logo}}{{end header_container_logo}}
6-
75
{{block mainmenu}}
86
{{<< mainmenu('apijson')}}
97
{{end mainmenu}}

demo/apps/apijson_demo/views.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44

55
@expose('/')
66
def index():
7-
request_data_list = [
7+
if request.user:
8+
user_info = "login as user '%s'"%(request.user)
9+
else:
10+
user_info = "not login, you can login with username 'usera/userb/userc', and password '123'"
11+
request_get = [
812
{
913
"label":"Single record query: with id as parameter",
1014
"value":'''{
@@ -42,6 +46,24 @@ def index():
4246
}''',
4347
},
4448
]
49+
50+
request_post = [
51+
{
52+
"label":"Add record",
53+
"value":'''{
54+
"Moment": {
55+
"content": "new moment for test",
56+
"pictureList": [
57+
"http://static.oschina.net/uploads/user/48/96331_50.jpg"
58+
]
59+
},
60+
"tag": "Moment"
61+
}''',
62+
},
63+
]
64+
4565
return {
46-
"request_data_list_json":dumps(request_data_list)
66+
"user_info":user_info,
67+
"request_get_json":dumps(request_get),
68+
"request_post_json":dumps(request_post),
4769
}

demo/apps/settings.ini

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ INSTALLED_APPS = [
1414
'uliweb.contrib.i18n',
1515
'uliweb.contrib.flashmessage',
1616
'uliweb_apps.site',
17+
'uliweb_apps.login',
1718
'uliweb_comui',
1819
'uliweb_apijson.apijson',
1920
'apijson_demo',
@@ -29,8 +30,11 @@ MAINMENU = {
2930
[APIJSON_MODEL]
3031
#overwrite user table to public for test
3132
user = {
32-
"public" : True,
3333
"user_id_field" : "id",
3434
"secret_fields" : ["password"],
3535
"default_filter_by_self" : True
3636
}
37+
38+
[LAYOUT]
39+
logo_lg = "Uliweb"
40+
logo_mini = "U"

demo/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ SQLAlchemy
66
-e git+https://github.com/uliwebext/uliweb-menu#egg=uliweb_menu
77
-e git+https://github.com/limodou/uliweb-apps#egg=uliweb_apps
88
-e git+https://github.com/zhangchunlin/uliweb-comapps#egg=uliweb_comapps
9-
-e git+https://github.com/zhangchunlin/uliweb-apijson#egg=uliweb_apijson
109
-e git+https://github.com/zhangchunlin/uliweb-comui#egg=uliweb_comui
10+
-e git+https://github.com/zhangchunlin/uliweb-apijson#egg=uliweb_apijson

0 commit comments

Comments
 (0)