from flask_security import current_user from advlabdb import assistantSpace, db from advlabdb.customClasses import SecureAssistantModelView from advlabdb.exceptions import DataBaseException, ModelViewException from advlabdb.models import ( Appointment, Assistant, Experiment, ExperimentMark, Group, GroupExperiment, Part, PartStudent, Program, Role, Semester, SemesterExperiment, Student, User, ) from advlabdb.utils import userActiveSemester class AssistantGroupExperimentView(SecureAssistantModelView): can_create = False can_edit = False can_delete = False column_display_actions = False column_list = ["group", "semester_experiment", "appointments", "experiment_marks"] column_filters = ["group", "semester_experiment.experiment", "appointments"] def queryFilter1(self): return GroupExperiment.group.has(Group.semester == userActiveSemester()) def queryFilter2(self): return GroupExperiment.semester_experiment.has( SemesterExperiment.assistants.any(Assistant.user == current_user) ) def get_query(self): return super().get_query().filter(self.queryFilter1()).filter(self.queryFilter2()) def get_count_query(self): return super().get_count_query().filter(self.queryFilter1()).filter(self.queryFilter2()) assistantSpace.add_view( AssistantGroupExperimentView( GroupExperiment, db.session, endpoint="assistant_groupexperiment", url="groupexperiment" ) )