-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·62 lines (47 loc) · 1.71 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Management script."""
import os
from flask import current_app
from flask import g, request
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager, Server, Shell
from flask_script.commands import ShowUrls, Clean
from user.app import create_app
from user.settings import DevConfig, ProdConfig, LocalConfig
from user.extensions import db
my_env = os.environ.get('USER_TEMPLATE_ENV')
if my_env == 'prod':
CONFIG = ProdConfig
elif my_env == 'dev':
CONFIG = DevConfig
else:
CONFIG = LocalConfig
HERE = os.path.abspath(os.path.dirname(__file__))
TEST_PATH = os.path.join(HERE, 'tests')
app = create_app(CONFIG)
manager = Manager(app)
migrate = Migrate(app, db)
def _make_context():
"""Return context dict for a shell session so you can access app, db, and the User model by default."""
return {'app': app, 'db': db}
@app.before_request
def before_request():
if current_app.config['DEBUG']:
print(request.headers)
@app.after_request
def after_request(response):
# cross domain setting
response.headers.add('Access-Control-Allow-Origin', app.config['ACAO'])
response.headers.add('Access-Control-Allow-Headers',
'Content-Type,Authorization,If-Modified-Since')
response.headers.add('Access-Control-Allow-Methods', 'GET,POST,PUT,DELETE')
response.headers.add('Access-Control-Allow-Credentials', 'true')
return response
manager.add_command('server', Server())
manager.add_command('shell', Shell(make_context=_make_context))
manager.add_command('urls', ShowUrls())
manager.add_command('db', MigrateCommand)
manager.add_command('clean', Clean())
if __name__ == '__main__':
manager.run()