-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
executable file
·105 lines (85 loc) · 4.34 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
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
#!/usr/bin/env python
#coding=utf-8
import os
from flask.ext.script import Server, Shell, Manager, prompt_bool
from pypackage import create_app
from pypackage.extensions import db
from pypackage.models import User
env = os.environ.get('PYPACKAGE_ENV', 'Dev')
app = create_app('pypackage.settings.%sConfig' % env.capitalize(), env=env)
manager = Manager(app)
# 添加shell中支持的环境
def _make_context():
return dict(db=db)
manager.add_command("shell", Shell(make_context=_make_context))
manager.add_command("runserver", Server('0.0.0.0', port=8000))
@manager.command
def syncdb():
"Creates database tables"
db.create_all()
@manager.command
def dropall():
"Drops all database tables"
if prompt_bool("Are you sure ? You will lose all your data !"):
db.drop_all()
@manager.command
def populate(default_data=False, sample_data=False):
"Populate database with default data"
if default_data:
db.session.execute("delete from items")
# db.session.add(Item(1, u'性别', 1001, 1, u'男'))
# db.session.add(Item(1, u'性别', 1002, 2, u'女'))
# db.session.add(Item(2, u'婚姻状况', 2001, 1, u'单身'))
# db.session.add(Item(2, u'婚姻状况', 2002, 2, u'已婚'))
# db.session.add(Item(2, u'婚姻状况', 2003, 3, u'离异'))
# # 维修工单
# db.session.add(Item(20, u'服务性质', 20001, 1, u'自费'))
# db.session.add(Item(20, u'服务性质', 20002, 2, u'保修'))
# db.session.add(Item(20, u'服务性质', 20003, 3, u'返修'))
# db.session.add(Item(20, u'服务性质', 20004, 4, u'自费不结算'))
# db.session.add(Item(20, u'服务性质', 20005, 5, u'自费待收费'))
# db.session.add(Item(20, u'服务性质', 20006, 6, u'保修不结算'))
# db.session.add(Item(20, u'服务性质', 20007, 7, u'保修待收费'))
# db.session.add(Item(20, u'服务性质', 20008, 8, u'过保减免'))
# db.session.add(Item(20, u'服务性质', 20009, 9, u'顾客不接受'))
# db.session.add(Item(20, u'服务性质', 20010, 10, u'用户咨询'))
# db.session.add(Item(20, u'服务性质', 20011, 11, u'已不需要处理'))
# db.session.add(Item(20, u'服务性质', 20012, 12, u'暂不确定'))
# db.session.add(Item(21, u'信息来源', 21001, 1, u'用户送修'))
# db.session.add(Item(21, u'信息来源', 21002, 2, u'电话接单'))
# db.session.add(Item(21, u'信息来源', 21003, 3, u'站内载机'))
# db.session.add(Item(21, u'信息来源', 21004, 4, u'800转单'))
# db.session.add(Item(21, u'信息来源', 21005, 5, u'400转单'))
# db.session.add(Item(21, u'信息来源', 21006, 6, u'广州转单'))
# db.session.add(Item(21, u'信息来源', 21007, 7, u'商场报单'))
# db.session.add(Item(21, u'信息来源', 21008, 8, u'商场送修'))
# db.session.add(Item(22, u'措施类别', 22001, 1, u'等回复'))
# db.session.add(Item(22, u'措施类别', 22002, 2, u'等零件'))
# db.session.add(Item(22, u'措施类别', 22003, 3, u'其它原因'))
# db.session.add(Item(22, u'措施类别', 22004, 4, u'QC'))
# db.session.add(Item(22, u'措施类别', 22005, 5, u'故障不稳定'))
# db.session.add(Item(22, u'措施类别', 22006, 6, u'中修'))
# db.session.add(Item(22, u'措施类别', 22007, 7, u'修复'))
# db.session.add(Item(22, u'措施类别', 22008, 8, u'送修工厂'))
# db.session.add(Item(22, u'措施类别', 22009, 9, u'在3'))
# db.session.add(Item(22, u'措施类别', 22010, 10, u'在4'))
# db.session.add(Item(22, u'措施类别', 22011, 11, u'在5'))
# db.session.add(Item(22, u'措施类别', 22012, 12, u'指导使用'))
# db.session.add(Item(23, u'用户类型', 23001, 1, u'普通用户'))
# db.session.add(Item(23, u'用户类型', 23002, 2, u'延保用户'))
db.session.commit()
# if sample_data:
# from fixtures.sample_data import all
# sample_data = dbfixture.data(*all)
# sample_data.setup()
@manager.command
def createadmin():
"Create admin and password is admin"
admin = User()
admin.username = "admin"
admin.password = "admin"
admin.supperuser = True
db.session.add(admin)
db.session.commit()
if __name__ == "__main__":
manager.run()