diff --git a/advlabdb/assistantModelViews.py b/advlabdb/assistantModelViews.py index 26c1228..08bcebd 100644 --- a/advlabdb/assistantModelViews.py +++ b/advlabdb/assistantModelViews.py @@ -42,17 +42,24 @@ assistantSpace = FlaskAdmin( class AssistantGroupExperimentView(SecureAssistantModelView): def is_accessible(self): - active_semester = current_user.active_semester - if active_semester.done: - flash( - Markup( - f"Active semester {active_semester} is marked as done. Therefore, you are not allowed to view or edit any marks in this semester. You should change your active semester in user settings." - ), - "danger", - ) + if not super().is_accessible(): return False - return super().is_accessible() + active_semester = current_user.active_semester + + if active_semester.done: + semester_changed = current_user.set_last_semester_as_active() + + if not semester_changed: + flash( + Markup( + f"Active semester {active_semester} is marked as done. Therefore, you are not allowed to view or edit any marks in this semester. You should change your active semester in user settings if possible." + ), + "danger", + ) + return False + + return True column_display_actions = True @@ -211,7 +218,7 @@ class AssistantUserView(SecureAssistantModelView): query_factory=semesterQueryFactory, validators=[DataRequired()], default=Semester.lastSemester, - description="You should change the active semester to the last semester. Do not forget to click save!", + description="You should change the active semester to the last semester. Do not forget to click save! Only last two semesters are shown that are not marked as done.", ) phone_number, mobile_phone_number, building, room = user_info_fields()