forked from pdokoupil/EasyStudy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
93 lines (68 loc) · 2.59 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import flask
from flask_pluginkit import PluginManager
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_wtf.csrf import CSRFProtect
from flask_session import Session
db = SQLAlchemy()
pm = PluginManager(plugins_folder="plugins")
csrf = CSRFProtect()
sess = Session()
# Insert/set all values that have to be set once (e.g. insert interaction types into DB)
def initialize_db_tables():
pass
# from models import InteractionType
# # If it has not been inserted yet, insert selected-item interaction type
# if db.session.query(
# db.session.query(InteractionType).filter_by(name='selected-item').exists()
# ).scalar():
# x = InteractionType()
# x.name = "selected-item"
# db.session.add(x)
# # If it has not been inserted yet, insert deselected-item interaction type
# if db.session.query(
# db.session.query(InteractionType).filter_by(name='deselected-item').exists()
# ).scalar():
# x = InteractionType()
# x.name = "deselected-item"
# db.session.add(x)
# # If it has not been inserted yet, insert changed-viewport type
# if db.session.query(
# db.session.query(InteractionType).filter_by(name='changed-viewport').exists()
# ).scalar():
# x = InteractionType()
# x.name = "changed-viewport"
# db.session.add(x)
# # If it has not been inserted yet, insert clicked-button type
# if db.session.query(
# db.session.query(InteractionType).filter_by(name='clicked-button').exists()
# ).scalar():
# x = InteractionType()
# x.name = "clicked-button"
# db.session.add(x)
def create_app():
app = flask.Flask(__name__)
app.config['SECRET_KEY'] = '8bf29bd88d0bfb94509f5fb0'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///db.sqlite'
app.config['SESSION_COOKIE_NAME'] = "something"
app.config["SESSION_TYPE"] = "filesystem"
sess.init_app(app)
db.init_app(app)
csrf.init_app(app)
login_manager = LoginManager(app)
pm.init_app(app)
from models import User
@login_manager.user_loader
def user_loader(user_id):
"""Given *user_id*, return the associated User object.
:param unicode user_id: user_id (email) user to retrieve
"""
return User.query.get(user_id)
from main import main as main_blueprint
app.register_blueprint(main_blueprint)
from auth import auth as auth_blueprint
app.register_blueprint(auth_blueprint)
with app.app_context():
db.create_all()
initialize_db_tables()
return app