forked from mitodl/mit_lti_flask_sample
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openhpi_lti_flask_sample.py
69 lines (51 loc) · 1.56 KB
/
openhpi_lti_flask_sample.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
64
65
66
67
68
69
import os
import sys
import logging
from flask import Flask
from orator import (
DatabaseManager,
Model
)
import config
def setup_database():
""" enable database
"""
from orator import DatabaseManager, Model
db = DatabaseManager(config.DATABASES)
Model.set_connection_resolver(db)
def setup_logging(loglevel=logging.DEBUG):
""" enable debug logging
:param loglevel: logging level
"""
logger = logging.getLogger()
logger.setLevel(loglevel)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(loglevel)
formatter = logging.Formatter('%(name)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
def setup_app():
""" create and setup flask app
:return: flask app
"""
# import the individual exercise controller (as blueprints)
from index import index_blueprint
from exercises.add import add_blueprint
from exercises.multiply import multiply_blueprint
from exercises.divide import divide_blueprint
# initiiate database
setup_database()
app = Flask(__name__)
app.config.from_object(config)
# register front controller
app.register_blueprint(index_blueprint)
# register exercise controller
app.register_blueprint(add_blueprint)
app.register_blueprint(multiply_blueprint)
app.register_blueprint(divide_blueprint)
return app
if __name__ == '__main__':
app = setup_app()
port = int(os.environ.get("FLASK_LTI_PORT", 5000))
host = os.environ.get("FLASK_LTI_HOST", '0.0.0.0')
app.run(debug=True, host=host, port=port)