3636from app .training_manager import TrainingManager
3737from app .utils import ALLOWED_EXTENSIONS , DEFAULT_EXTENSION
3838
39- app = Flask (__name__ )
40- app .register_blueprint (api_audio )
41- app .register_blueprint (api_dump )
42- app .register_blueprint (api_criteria )
43- app .register_blueprint (api_criteria_pack )
44- app .register_blueprint (api_files )
45- app .register_blueprint (api_logs )
46- app .register_blueprint (api_presentations )
47- app .register_blueprint (api_sessions )
48- app .register_blueprint (api_task_attempts )
49- app .register_blueprint (api_trainings )
50- app .register_blueprint (api_version )
51- app .register_blueprint (routes_admin )
52- app .register_blueprint (routes_criterion )
53- app .register_blueprint (routes_criteria_pack )
54- app .register_blueprint (routes_lti )
55- app .register_blueprint (routes_presentations )
56- app .register_blueprint (routes_trainings )
57- app .register_blueprint (routes_task_attempts )
58- app .register_blueprint (routes_version )
59- app .register_blueprint (routes_capacity )
39+
40+
6041
6142logger = get_root_logger (service_name = 'web' )
6243
@@ -90,70 +71,95 @@ def resubmit_failed_trainings():
9071 TrainingManager ().add_training (current_training .pk )
9172
9273
93- @app .route ('/' , methods = ['GET' ])
94- def index ():
95- return render_template ('intro_page.html' )
96-
97-
98-
99- @app .route ('/init/' , methods = ['GET' ])
100- def init ():
101- """
102- Route for session initialization. Enabled only if is_testing_active returns True.
10374
104- :return: Empty dictionary
105- """
106- from app .utils import is_testing_active
107- if not is_testing_active ():
108- return {}, 200
109- session ['session_id' ] = Config .c .testing .session_id
110- session ['full_name' ] = Config .c .testing .lis_person_name_full
111- session ['consumer_key' ] = Config .c .testing .oauth_consumer_key
112- session ['task_id' ] = Config .c .testing .custom_task_id
113- session ['criteria_pack_id' ] = Config .c .testing .custom_criteria_pack_id
114- session ['feedback_evaluator_id' ] = Config .c .testing .custom_feedback_evaluator_id
115- session ['formats' ] = list (set (Config .c .testing .custom_formats .split (',' )) & ALLOWED_EXTENSIONS ) or [DEFAULT_EXTENSION ]
116- from app .mongo_odm import TasksDBManager , TaskAttemptsDBManager
117- session ['task_attempt_id' ] = str (TaskAttemptsDBManager ().add_task_attempt (
118- username = session ['session_id' ],
119- task_id = session ['task_id' ],
120- params_for_passback = {
121- 'lis_outcome_service_url' : Config .c .testing .lis_outcome_service_url ,
122- 'lis_result_sourcedid' : Config .c .testing .lis_result_source_did ,
123- 'oauth_consumer_key' : Config .c .testing .oauth_consumer_key ,
124- },
125- training_count = 3 ,
126- ).pk )
127- TasksDBManager ().add_task_if_absent (
128- Config .c .testing .custom_task_id ,
129- Config .c .testing .custom_task_description ,
130- int (Config .c .testing .custom_attempt_count ),
131- float (Config .c .testing .custom_required_points ),
132- Config .c .testing .custom_criteria_pack_id ,
133- )
134- return {}, 200
135-
136-
137- def setupLocales (locale : str , default : str = "ru" ):
75+ def setupLocales (app : Flask , locale : str , default : str = "ru" ):
13876 loadLocales ("./locale" )
13977 changeLocale (locale , default )
14078 setupTemplatesAlias (app )
14179
142-
143- if __name__ == '__main__' :
144- Config .init_config (sys .argv [1 ])
80+ def initApp (config_path = None ):
81+ app = Flask (__name__ )
82+
83+ Config .init_config (config_path )
84+
14585 werkzeug_logger = logging .getLogger ('werkzeug' )
14686 werkzeug_logger .addHandler (get_logging_stdout_handler ())
14787 werkzeug_logger .setLevel (logging .ERROR )
14888 werkzeug_logger .propagate = False
89+
14990 app .logger .addHandler (get_logging_stdout_handler ())
15091 app .logger .propagate = False
92+
15193 app .wsgi_app = ReverseProxied (app .wsgi_app )
15294 app .secret_key = Config .c .constants .app_secret_key
15395
15496 app .config ['BUG_REPORT_FORM' ] = Config .c .bugreport .form_link
15597 app .config ['BUG_REPORT_MAIL' ] = Config .c .bugreport .report_mail
15698
99+ app .register_blueprint (api_audio )
100+ app .register_blueprint (api_dump )
101+ app .register_blueprint (api_criteria )
102+ app .register_blueprint (api_criteria_pack )
103+ app .register_blueprint (api_files )
104+ app .register_blueprint (api_logs )
105+ app .register_blueprint (api_presentations )
106+ app .register_blueprint (api_sessions )
107+ app .register_blueprint (api_task_attempts )
108+ app .register_blueprint (api_trainings )
109+ app .register_blueprint (api_version )
110+ app .register_blueprint (routes_admin )
111+ app .register_blueprint (routes_criterion )
112+ app .register_blueprint (routes_criteria_pack )
113+ app .register_blueprint (routes_lti )
114+ app .register_blueprint (routes_presentations )
115+ app .register_blueprint (routes_trainings )
116+ app .register_blueprint (routes_task_attempts )
117+ app .register_blueprint (routes_version )
118+ app .register_blueprint (routes_capacity )
119+
120+ @app .route ('/' , methods = ['GET' ])
121+ def index ():
122+ return render_template ('intro_page.html' )
123+
124+
125+
126+ @app .route ('/init/' , methods = ['GET' ])
127+ def init ():
128+ """
129+ Route for session initialization. Enabled only if is_testing_active returns True.
130+
131+ :return: Empty dictionary
132+ """
133+ from app .utils import is_testing_active
134+ if not is_testing_active ():
135+ return {}, 200
136+ session ['session_id' ] = Config .c .testing .session_id
137+ session ['full_name' ] = Config .c .testing .lis_person_name_full
138+ session ['consumer_key' ] = Config .c .testing .oauth_consumer_key
139+ session ['task_id' ] = Config .c .testing .custom_task_id
140+ session ['criteria_pack_id' ] = Config .c .testing .custom_criteria_pack_id
141+ session ['feedback_evaluator_id' ] = Config .c .testing .custom_feedback_evaluator_id
142+ session ['formats' ] = list (set (Config .c .testing .custom_formats .split (',' )) & ALLOWED_EXTENSIONS ) or [DEFAULT_EXTENSION ]
143+ from app .mongo_odm import TasksDBManager , TaskAttemptsDBManager
144+ session ['task_attempt_id' ] = str (TaskAttemptsDBManager ().add_task_attempt (
145+ username = session ['session_id' ],
146+ task_id = session ['task_id' ],
147+ params_for_passback = {
148+ 'lis_outcome_service_url' : Config .c .testing .lis_outcome_service_url ,
149+ 'lis_result_sourcedid' : Config .c .testing .lis_result_source_did ,
150+ 'oauth_consumer_key' : Config .c .testing .oauth_consumer_key ,
151+ },
152+ training_count = 3 ,
153+ ).pk )
154+ TasksDBManager ().add_task_if_absent (
155+ Config .c .testing .custom_task_id ,
156+ Config .c .testing .custom_task_description ,
157+ int (Config .c .testing .custom_attempt_count ),
158+ float (Config .c .testing .custom_required_points ),
159+ Config .c .testing .custom_criteria_pack_id ,
160+ )
161+ return {}, 200
162+
157163 # check correct criterions
158164 if not check_criterions (CRITERIONS ):
159165 logging .critical ("Criterion's checking failed! See traceback" )
@@ -167,6 +173,10 @@ def setupLocales(locale: str, default: str = "ru"):
167173 ConsumersDBManager ().add_consumer (Config .c .constants .lti_consumer_key , Config .c .constants .lti_consumer_secret )
168174 resubmit_failed_trainings ()
169175
170- setupLocales (Config .c .locale .language )
176+ setupLocales (app , Config .c .locale .language )
177+
178+ return app
171179
180+ if __name__ == '__main__' :
181+ app = initApp (sys .argv [1 ])
172182 app .run (host = '0.0.0.0' )
0 commit comments