-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
88 lines (70 loc) · 2.37 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
from typing import Optional, Type
from dotenv import load_dotenv
from flask import Flask, render_template
from application.translations import get_current_language, get_translation
from config import Config, get_config
from logging_config import setup_logging
load_dotenv()
def create_app(config_class: Optional[Type[Config]] = None) -> Flask:
"""
Create and configure the Flask application.
Args:
config_class: Optional configuration class to use instead of default
Returns:
Configured Flask application instance
"""
app = Flask(
__name__,
template_folder="application/templates",
static_folder="application/static",
)
setup_logging()
# Load configuration
if config_class is None:
app.config.from_object(get_config())
else:
app.config.from_object(config_class)
app.secret_key = app.config["SECRET_KEY"]
# Register template utilities
@app.context_processor
def utility_processor() -> dict:
"""Make utility functions available to all templates."""
return {
"get_current_language": get_current_language,
"get_translation": get_translation,
}
# Register error handlers
@app.errorhandler(400)
def bad_request(e):
"""Handle 400 Bad Request errors."""
return (
render_template(
"error.html",
message=e.description,
),
400,
)
@app.errorhandler(404)
def not_found(e):
"""Handle 404 Not Found errors."""
return (
render_template(
"error.html",
message=e.description,
),
404,
)
from application.routes.answers import answers_routes
from application.routes.dashboard import dashboard_routes
from application.routes.report import report_routes
from application.routes.survey import survey_routes
from application.routes.utils import util_routes
app.register_blueprint(util_routes)
app.register_blueprint(survey_routes, url_prefix="/")
app.register_blueprint(report_routes)
app.register_blueprint(dashboard_routes)
app.register_blueprint(answers_routes, url_prefix="/answers")
return app
app = create_app()
if __name__ == "__main__":
app.run(host="0.0.0.0", port=app.config["PORT"], debug=app.config["DEBUG"])