-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
46 lines (33 loc) · 958 Bytes
/
run.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
"""
Application entry point.
"""
import os
import logging as lg
from core import create_app, db
from flask_migrate import Migrate
from core.models import Role, User, Post, Comment
from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), '.flaskenv')
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
app = create_app(os.getenv('FLASK_CONFIG') or 'dev')
migrate = Migrate(app, db, render_as_batch=True)
@app.shell_context_processor
def make_shell_context():
return dict(
db=db, Role=Role,
User=User, Post=Post, Comment=Comment
)
@app.cli.command('test')
def test():
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
@app.cli.command('init_db')
def init_db():
db.create_all()
Role.insert_roles()
db.session.commit()
lg.warning('Database initialized !')
if __name__ == "__main__":
app.run()