__init__.py
1.37 KB
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
import os
import sys
from flask import Flask
from app.models import db
# Please, set a config file on top project dir
# find example in ressources/pdc_config.py
try:
from pdc_config import Config, ProdConfig, DevConfig, TestConfig
except ImportError:
# TODO: use logging system
print("Please set an pdc_config.py file in you PYTHON_PATH")
print("See INSTALL.md for more info")
sys.exit(-1)
def create_app(config_class=None):
""" App Factory.
can be called with configuration class as argument.
"""
# Configuration Switcher
# try to set configuration depending on environment
# if no configuration class was given
#
if config_class is None:
flask_env = os.environ.get('FLASK_ENV')
if not flask_env:
flask_env = 'testing'
if flask_env == 'production':
config_class = ProdConfig
elif flask_env == 'development':
config_class = DevConfig
elif flask_env == 'testing':
config_class = TestConfig
else:
config_class = Config
# Main flask app
#
app = Flask(__name__)
app.config.from_object(config_class)
db.init_app(app)
# Get and activate blueprints
#
from .main import bp as main_bp
app.register_blueprint(main_bp)
from .auth import bp as auth_bp
app.register_blueprint(auth_bp)
return app