Skip to content

Commit ebac85f

Browse files
committed
add first version of uliweb_apijson.apijson and demo project
1 parent 04263ce commit ebac85f

26 files changed

+872
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
uliweb-apijson is a subset and slightly different variation of [apijson](https://github.com/TommyLemon/APIJSON/blob/master/Document.md)
2+
3+
You can try:
4+
5+
- [Demo uliweb project](demo/README.md)
6+
- [uliweb-apijson document](uliweb_apijson/apijson/README.md)

demo/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.pyc
2+
*.bak
3+
local_settings.ini
4+
build
5+
dist
6+
*.egg-info
7+
.idea
8+
_git
9+
data
10+
database.db

demo/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## How to run uliweb-apijson demo?
2+
3+
pip install dependent packages, in demo root directory run:
4+
5+
```
6+
pip install six
7+
pip install -r requirements.txt
8+
```
9+
10+
In demo root directory,run commands to init db:
11+
12+
```
13+
uliweb syncdb
14+
uliweb dbinit
15+
```
16+
17+
In demo root directory, run debug server:
18+
19+
```
20+
uliweb runserver
21+
```
22+
23+
Then you can access http://localhost:8000 to try demo.
24+
25+
![](doc/imgs/demo_screenshot.png)

demo/apps/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
__version__ = '0.1'
2+
__url__ = ''
3+
__author__ = ''
4+
__email__ = ''
File renamed without changes.

demo/apps/apijson_demo/__init__.py

Whitespace-only changes.

demo/apps/apijson_demo/dbinit.py

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
#coding=utf-8
2+
from uliweb import models
3+
from uliweb.orm import set_dispatch_send
4+
5+
set_dispatch_send(False)
6+
7+
User = models.user
8+
Privacy = models.privacy
9+
Comment = models.comment
10+
Moment = models.moment
11+
12+
user_list = [
13+
{
14+
"username": "usera",
15+
"nickname": "User A",
16+
"email": "usera@localhost",
17+
},
18+
{
19+
"username": "userb",
20+
"nickname": "User B",
21+
"email": "userb@localhost",
22+
},
23+
{
24+
"username": "userc",
25+
"nickname": "User C",
26+
"email": "userc@localhost",
27+
},
28+
]
29+
30+
privacy_list = [
31+
{
32+
"username" : "usera",
33+
"certified" : True,
34+
"phone" : "13333333333",
35+
"balance" : 100,
36+
"password" : "hash_of_123",
37+
"paypassword" : "hash_of_sudfy8e7r",
38+
},
39+
{
40+
"username" : "userb",
41+
"certified" : True,
42+
"phone" : "12222222222",
43+
"balance" : 130,
44+
"password" : "hash_of_dfdfd",
45+
"paypassword" : "hash_of_234erere",
46+
},
47+
{
48+
"username" : "userc",
49+
"certified" : True,
50+
"phone" : "14323424234",
51+
"balance" : 600,
52+
"password" : "hash_of_w3erere",
53+
"paypassword" : "hash_of_ghtwertr",
54+
},
55+
]
56+
57+
moment_list = [
58+
{
59+
"username" : "usera",
60+
"date" : "2018-11-1",
61+
"content" : "test moment",
62+
},
63+
{
64+
"username" : "userb",
65+
"date" : "2018-11-2",
66+
"content" : "test moment from b",
67+
},
68+
{
69+
"username" : "userc",
70+
"date" : "2018-11-6",
71+
"content" : "test moment from c",
72+
},
73+
]
74+
75+
comment_list = [
76+
{
77+
"username" : "usera",
78+
"to_username" : "userb",
79+
"moment_id" : 1,
80+
"date" : "2018-12-1",
81+
"content" : "comment haha",
82+
},
83+
{
84+
"username" : "userb",
85+
"to_username" : "usera",
86+
"moment_id" : 2,
87+
"date" : "2018-12-2",
88+
"content" : "comment xixi",
89+
},
90+
{
91+
"username" : "userc",
92+
"to_username" : "usera",
93+
"moment_id" : 3,
94+
"date" : "2018-12-9",
95+
"content" : "comment hoho",
96+
},
97+
]
98+
99+
for d in user_list:
100+
if not User.get(User.c.username==d["username"]):
101+
print("create user '%s'"%(d["username"]))
102+
User(**d).save()
103+
for d in privacy_list:
104+
user = User.get(User.c.username==d["username"])
105+
if user:
106+
d["user_id"] = user.id
107+
print("create privacy record for user '%s'"%(d["username"]))
108+
Privacy(**d).save()
109+
else:
110+
print("error: unknown user '%s'"%(d["username"]))
111+
112+
for d in moment_list:
113+
user = User.get(User.c.username==d["username"])
114+
if user:
115+
d["user_id"] = user.id
116+
print("create moment record for user '%s'"%(d["username"]))
117+
Moment(**d).save()
118+
else:
119+
print("error: unknown user '%s'"%(d["username"]))
120+
121+
122+
for d in comment_list:
123+
user = User.get(User.c.username==d["username"])
124+
if user:
125+
d["user_id"] = user.id
126+
d["to_id"] = User.get(User.c.username==d["to_username"]).id
127+
print("create comment record for user '%s'"%(d["username"]))
128+
Comment(**d).save()
129+
else:
130+
print("error: unknown user '%s'"%(d["username"]))

demo/apps/apijson_demo/models.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#coding=utf-8
2+
3+
from uliweb.orm import *
4+
5+
class Privacy(Model):
6+
user_id = Reference("user")
7+
certified = Field(bool)
8+
phone = Field(str)
9+
balance = Field(DECIMAL)
10+
password = Field(str)
11+
paypassword = Field(str)
12+
13+
class Moment(Model):
14+
user_id = Reference("user")
15+
date = Field(datetime.datetime, auto_now_add=True)
16+
content = Field(TEXT)
17+
18+
class Comment(Model):
19+
user_id = Reference("user")
20+
to_id = Reference("user")
21+
moment_id = Reference("moment")
22+
date = Field(datetime.datetime, auto_now_add=True)
23+
content = Field(TEXT)

demo/apps/apijson_demo/settings.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[MODELS]
2+
privacy = 'apijson_demo.models.Privacy'
3+
comment = 'apijson_demo.models.Comment'
4+
moment = 'apijson_demo.models.Moment'

0 commit comments

Comments
 (0)