This repository has been archived by the owner on Jan 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
manage.py
63 lines (52 loc) · 2.81 KB
/
manage.py
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
from flask_script import Manager, Server
from flask_migrate import Migrate, MigrateCommand
from app.models import *
from app import app
manager = Manager()
manager.add_command('server', Server())
migrate = Migrate(app, db)
manager = Manager(app)
manager.add_command('db', MigrateCommand)
def create_roles():
"""
创建角色表
shell里运行create_roles创建角色
"""
roles = {
'User': Permission.NAME_MODIFY | Permission.AVATAR_MODIFY | Permission.COMMENT | Permission.SHARE |
Permission.REPORT | Permission.ORDER_SUBMIT | Permission.FOLLOW | Permission.DESIGNER_APPLY |
Permission.WORK_MANAGE | Permission.SHOWCASE_MANAGE,
'Designer': Permission.NAME_MODIFY | Permission.AVATAR_MODIFY | Permission.COMMENT | Permission.SHARE |
Permission.REPORT | Permission.ORDER_SUBMIT | Permission.FOLLOW | Permission.DESIGNER_APPLY |
Permission.WORK_MANAGE | Permission.SHOWCASE_MANAGE | Permission.ORDER_RECEIVED_WRITE | Permission.ORDER_DEAL |
Permission.BILLBOARD_WORK_CONFIRM | Permission.SUPER_DESIGNER_APPLY,
'SuperDesigner': Permission.NAME_MODIFY | Permission.AVATAR_MODIFY | Permission.COMMENT | Permission.SHARE |
Permission.REPORT | Permission.ORDER_SUBMIT | Permission.FOLLOW | Permission.DESIGNER_APPLY |
Permission.WORK_MANAGE | Permission.SHOWCASE_MANAGE | Permission.ORDER_RECEIVED_WRITE | Permission.ORDER_DEAL |
Permission.BILLBOARD_WORK_CONFIRM,
'Admin': Permission.NAME_MODIFY | Permission.AVATAR_MODIFY | Permission.COMMENT | Permission.SHARE |
Permission.REPORT | Permission.ORDER_SUBMIT | Permission.FOLLOW | Permission.DESIGNER_APPLY |
Permission.WORK_MANAGE | Permission.SHOWCASE_MANAGE | Permission.ORDER_RECEIVED_WRITE | Permission.ORDER_DEAL |
Permission.BILLBOARD_WORK_CONFIRM | Permission.SUPER_DESIGNER_APPLY | Permission.ADMIN,
'Banned': Permission.BANNED
}
for r in roles:
role = Role.query.filter_by(name=r).first()
if role is None:
role = Role(name=r)
role.permission = roles[r]
db.session.add(role)
db.session.commit()
# 创建一个空的作品类型
def create_null_category():
null_category = Category(id=1,name='no_name',description='No any category')
db.session.add(null_category)
db.session.commit()
@manager.shell
def make_shell_context():
return dict(app=app, db=db, role=Role, user=User, category=Category, picture=Picture, video=Video, order=Order,
star_video=StarVideo, star_picture=StarPicture, showcase=ShowCase, tag=Tag,
comment_video=CommentVideo, comment_picture=CommentPicture, create_roles=create_roles,
create_null_category=create_null_category, backend_user=BackendUser, order_extra=OrderExtra)
if __name__ == '__main__':
manager.run()