-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
51 lines (33 loc) · 1.21 KB
/
app.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
import os
def register_commands(app):
import click
@click.command()
@click.option('--length', default=25)
@click.option('--profile-dir', default=None)
def profile(length, profile_dir):
from werkzeug.contrib.profiler import ProfilerMiddleware
from core import create_app
app = create_app()
app.wsgi_app = ProfilerMiddleware(app.wsgi_app,
restrictions=(length, ),
profile_dir=profile_dir)
app.run(debug=False)
def set_shellcontext(app):
from models import Pink, Pit, Proj
from core.singleton import db
def shell_context():
return {'app': app, 'db': db, 'Pink': Pink, 'Proj': Proj, 'Pit': Pit}
app.shell_context_processor(shell_context)
def create_manager(env=os.getenv('FLASK_ENV', 'production')):
from flask import Flask
from flask_migrate import Migrate
from configs import load_config
from core.singleton import db
app = Flask(__name__)
app.config.from_object(load_config(env))
db.init_app(app)
migrate = Migrate(app, db)
set_shellcontext(app)
register_commands(app)
return app
application = create_manager()