@@ -27,6 +27,18 @@ def correct_message(text):
2727 return (len (text ) != 0 )
2828
2929
30+ @require_logged_in
31+ def change_thread_score (thread : Thread , score : float ) -> None :
32+ """Change thread score (if necessary) and notify student in a dialog"""
33+
34+ if thread .score != score :
35+ score_change_msg = f"Балл изменен. Текущий балл: { score } ."
36+ Post .create (text = score_change_msg , date = datetime .datetime .now (),
37+ author = g .user , thread = thread ,
38+ hide_from_student = False )
39+ thread .update (score = score ).execute ()
40+
41+
3042@require_logged_in
3143def thread_page (task_id : int , student_id : int ) -> Response :
3244 """GET /thread/{task}/{student}: show specified thread"""
@@ -51,15 +63,15 @@ def post_to_thread(task_id: int, student_id: int) -> Response:
5163 hide_from_student = g .user .is_teacher and request .form .get ('hide_from_student' , False )
5264
5365 if correct_message (text ):
54- if g .user .is_teacher :
55- score = request .form .get ('score' )
56- if thread .score != score :
57- thread .update (score = score ).execute ()
58-
5966 Post .create (text = text , date = datetime .datetime .now (),
6067 author = g .user , thread = thread ,
6168 hide_from_student = hide_from_student )
6269 else :
6370 # TODO: redirect back to a dialogue, restoring a message draft not to lose it
6471 pass
72+
73+ if g .user .is_teacher :
74+ score = float (request .form .get ('score' ))
75+ change_thread_score (thread , score )
76+
6577 return redirect (url_for ('thread' , task_id = task_id , student_id = student_id ))
0 commit comments