-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.py
136 lines (115 loc) · 2.89 KB
/
init.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import os
from dotenv import load_dotenv
from flask import Flask, render_template
from flask_cors import CORS
from flask_login import LoginManager
from flask_talisman import Talisman
app = Flask(__name__)
# set up login manager
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = "users.login"
# setup database
from flask_migrate import Migrate
from models.user import db
# import views
from views.generate_download import MakeImageView
from views.pageviews import (
View,
DownloadView,
SignupView,
LoginView,
ContactView,
ThanksView,
PrivacyPolicyView,
QuizView,
ContributeView,
SettingsView,
StatisticsView,
GoalsView,
GrabCurrentUserView,
LogOutView,
FAQView,
TutorialView
)
from views.apiviews import (
JSONDataView,
ContactSubmitView, ReturnGoalsView,
UpdateBoxView,
DeleteBoxView,
ReadAllView,
CreateBoxView,
UpdateUserInfoView,
UpdateAttrView,
ReturnAttrView,
SimpleAttrUpdateView,
ReturnGoalsView,
DeleteUserView,
UpdateUserEmailView,
UpdateUserPasswordView,
ResetPasswordView,
ForgotPasswordView,
TotalUsersView
)
basedir = os.path.abspath(os.path.dirname(__file__))
app.config["SECRET_KEY"] = os.environ["APP_CONFIG_KEY"]
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ["DATABASE_URL"]
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
CORS(app, resources={r"/api/*": {"origins": "*"}})
db.init_app(app)
Migrate(app, db)
# force serving over HTTPS - DISABLE FOR TESTING
Talisman(app, content_security_policy=None)
load_dotenv()
def form_application() -> Flask:
@app.errorhandler(404)
def page_not_found(e):
return render_template("404.html"), 404
@app.errorhandler(403)
def access_forbidden(e):
return render_template("403.html"), 403
@app.errorhandler(500)
def server_error(e):
return render_template("500.html"), 500
register_views(app)
return app
def register_views(app):
# register individual views
views = [
View,
DownloadView,
JSONDataView,
SignupView,
LoginView,
ContactView,
ContactSubmitView,
ThanksView,
PrivacyPolicyView,
QuizView,
ContributeView,
SettingsView,
StatisticsView,
GoalsView,
CreateBoxView,
UpdateBoxView,
ReadAllView,
DeleteBoxView,
GrabCurrentUserView,
UpdateUserInfoView,
LogOutView,
UpdateAttrView,
ReturnAttrView,
SimpleAttrUpdateView,
ReturnGoalsView,
UpdateUserPasswordView,
UpdateUserEmailView,
DeleteUserView,
ResetPasswordView,
ForgotPasswordView,
FAQView,
TutorialView,
TotalUsersView
]
for view in views:
view.register(app)
MakeImageView.register(app, route_prefix="/api")