-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
63 lines (51 loc) · 1.54 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, Shell
from flask_migrate import Migrate, MigrateCommand
from app import create_app, db
from app.user.models import User, Role, Follow
from app.forum.models import Post, Topic, Comment
from app.message.models import Notification, NotifyConfig
from app.activity.models import Activity
from app.main.models import ImgFace, Tag
app = create_app('development')
manager = Manager(app)
migrate = Migrate(app, db)
def make_shell_context():
"""Return a dict of objects
eg:
>> python manage.py shell
>> app
<Flask 'app'>
"""
return dict(app=app, db=db, User=User,
Role=Role, Post=Post,
Topic=Topic, Comment=Comment,
notify=Notification,
NotifyConfig = NotifyConfig,
Activity=Activity,
Img=ImgFace, Tag=Tag)
manager.add_command("shell", Shell(make_context=make_shell_context))
manager.add_command('db', MigrateCommand)
@manager.command
def fake():
"""Generate testing data"""
db.drop_all()
db.create_all()
Role.insert_roles()
Topic.insert_topic()
User.generate_fake()
Post.generate_fake()
Comment.generate_fake()
Follow.generate_fake()
@manager.command
def test():
"""Run the unit tests"""
import unittest
# find all test files
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
@manager.command
def deploy():
Role.insert_roles()
Topic.insert_topic()
if __name__ == '__main__':
manager.run()