diff --git a/advlabdb/adminModelViews.py b/advlabdb/adminModelViews.py index 75763fe..f245edf 100644 --- a/advlabdb/adminModelViews.py +++ b/advlabdb/adminModelViews.py @@ -404,8 +404,8 @@ class PartView(SecureAdminModelView): column_searchable_list = ["program.label", "number"] - def queryFilter(self): - return Part.semester == current_user.active_semester + def query_modifier(self, query): + return query.where(Part.semester == current_user.active_semester) def customCreateModel(self, form): return Part(program=form.program.data, number=form.number.data, semester=current_user.active_semester) @@ -560,8 +560,8 @@ class PartStudentView(SecureAdminModelView): ), ] - def queryFilter(self): - return PartStudent.part.has(Part.semester == current_user.active_semester) + def query_modifier(self, query): + return query.join(Part).where(Part.semester == current_user.active_semester) def on_model_change(self, form, model, is_created): PartStudent.check(model.part, model.group) @@ -627,8 +627,8 @@ class GroupView(SecureAdminModelView): ) refreshFiltersCache = True - def queryFilter(self): - return Group.semester == current_user.active_semester + def query_modifier(self, query): + return query.wher(Group.semester == current_user.active_semester) def customCreateModel(self, form): return Group.customInit(form.part_students.data) @@ -788,8 +788,8 @@ class SemesterExperimentView(SecureAdminModelView): ), ] - def queryFilter(self): - return SemesterExperiment.semester == current_user.active_semester + def query_modifier(self, query): + return query.where(SemesterExperiment.semester == current_user.active_semester) def customCreateModel(self, form): return SemesterExperiment( @@ -1044,8 +1044,8 @@ class GroupExperimentView(SecureAdminModelView): ), ] - def queryFilter(self): - return GroupExperiment.group.has(Group.semester == current_user.active_semester) + def query_modifier(self, query): + return query.join(Group).where(Group.semester == current_user.active_semester) def customCreateModel(self, form): return GroupExperiment(semester_experiment=form.semester_experiment.data, group=form.group.data) @@ -1164,9 +1164,11 @@ class AppointmentView(SecureAdminModelView): ), ] - def queryFilter(self): - return Appointment.group_experiment.has( - GroupExperiment.semester_experiment.has(SemesterExperiment.semester == current_user.active_semester) + def query_modifier(self, query): + return ( + query.join(GroupExperiment) + .join(SemesterExperiment) + .where(SemesterExperiment.semester == current_user.active_semester) ) def customCreateModel(self, form): @@ -1340,9 +1342,11 @@ class ExperimentMarkView(SecureAdminModelView): """ # Deactivated for the experiments history of a student. - def queryFilter(self): - return ExperimentMark.group_experiment.has( - GroupExperiment.semester_experiment.has(SemesterExperiment.semester == current_user.active_semester) + def query_modifier(self, query): + return ( + query.join(GroupExperiment) + .join(SemesterExperiment) + .where(SemesterExperiment.semester == current_user.active_semester) ) """