forked from zhangchunlin/uliweb-apijson
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdbinit.py
More file actions
167 lines (155 loc) · 3.98 KB
/
dbinit.py
File metadata and controls
167 lines (155 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#coding=utf-8
from uliweb import models
from uliweb.orm import set_dispatch_send
set_dispatch_send(False)
User = models.user
Privacy = models.privacy
Comment = models.comment
Comment2 = models.comment2
Moment = models.moment
PublicNotice = models.publicnotice
user_list = [
{
"username": "admin",
"nickname": "Administrator",
"email": "admin@localhost",
"date_join": "2018-1-1 0:0:0",
},
{
"username": "usera",
"nickname": "User A",
"email": "usera@localhost",
"date_join": "2018-2-2 0:0:0",
},
{
"username": "userb",
"nickname": "User B",
"email": "userb@localhost",
"date_join": "2018-3-3 0:0:0",
},
{
"username": "userc",
"nickname": "User C",
"email": "userc@localhost",
"date_join": "2018-4-4 0:0:0",
},
]
privacy_list = [
{
"username" : "usera",
"certified" : True,
"phone" : "13333333333",
"balance" : 100,
"password" : "hash_of_123",
"paypassword" : "hash_of_sudfy8e7r",
},
{
"username" : "userb",
"certified" : True,
"phone" : "12222222222",
"balance" : 130,
"password" : "hash_of_dfdfd",
"paypassword" : "hash_of_234erere",
},
{
"username" : "userc",
"certified" : True,
"phone" : "14323424234",
"balance" : 600,
"password" : "hash_of_w3erere",
"paypassword" : "hash_of_ghtwertr",
},
]
moment_list = [
{
"username" : "usera",
"date" : "2018-11-1",
"content" : "test moment",
},
{
"username" : "userb",
"date" : "2018-11-2",
"content" : "test moment from b",
},
{
"username" : "userc",
"date" : "2018-11-6",
"content" : "test moment from c",
},
]
comment_list = [
{
"username" : "admin",
"to_username" : "userb",
"moment_id" : 1,
"date" : "2018-11-1",
"content" : "comment from admin",
},
{
"username" : "usera",
"to_username" : "userb",
"moment_id" : 1,
"date" : "2018-12-1",
"content" : "comment from usera to userb",
},
{
"username" : "userb",
"to_username" : "usera",
"moment_id" : 2,
"date" : "2018-12-2",
"content" : "comment from userb to usera",
},
{
"username" : "userc",
"to_username" : "usera",
"moment_id" : 3,
"date" : "2018-12-9",
"content" : "comment from userc to usera",
},
]
publicnotice_list = [
{
"date" : "2018-12-9",
"content" : "notice: a",
},
{
"date" : "2018-12-18",
"content" : "notice: b",
},
]
for d in user_list:
if not User.get(User.c.username==d["username"]):
print("create user '%s'"%(d["username"]))
u = User(**d)
u.set_password("123")
if d["username"]=="admin":
u.is_superuser = True
u.save()
for d in privacy_list:
user = User.get(User.c.username==d["username"])
if user:
d["user_id"] = user.id
print("create privacy record for user '%s'"%(d["username"]))
Privacy(**d).save()
else:
print("error: unknown user '%s'"%(d["username"]))
for d in moment_list:
user = User.get(User.c.username==d["username"])
if user:
d["user_id"] = user.id
print("create moment record for user '%s'"%(d["username"]))
Moment(**d).save()
else:
print("error: unknown user '%s'"%(d["username"]))
for d in comment_list:
user = User.get(User.c.username==d["username"])
if user:
d["user_id"] = user.id
d["to_id"] = User.get(User.c.username==d["to_username"]).id
print("create comment record for user '%s'"%(d["username"]))
Comment(**d).save()
Comment2(**d).save()
else:
print("error: unknown user '%s'"%(d["username"]))
for d in publicnotice_list:
PublicNotice(**d).save()