1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00

Improved filters

This commit is contained in:
Mo 2021-07-30 15:14:35 +02:00
parent e4b29a37d6
commit 8333da3c91
2 changed files with 14 additions and 30 deletions

View file

@ -118,7 +118,7 @@ class UserView(SecureAdminModelView):
if model == current_user and not form.active.data: if model == current_user and not form.active.data:
raise ModelViewException("Tried to deactiavte yourself as user!") raise ModelViewException("Tried to deactiavte yourself as user!")
if form.generate_new_password.data: if hasattr(form, "generate_new_password") and form.generate_new_password.data:
password = randomPassword() password = randomPassword()
UserView.flashPassword(password) UserView.flashPassword(password)
@ -248,7 +248,7 @@ class StudentView(SecureAdminModelView):
def partQueryFactory(): def partQueryFactory():
return Part.query.filter(Part.id.in_([part.id for part in userActiveSemester().parts])) return Part.query.filter(Part.semester == userActiveSemester())
def groupQueryFactory(): def groupQueryFactory():
@ -294,7 +294,7 @@ class PartStudentView(SecureAdminModelView):
column_filters = ["part", "student", "group"] column_filters = ["part", "student", "group"]
def queryFilter(self): def queryFilter(self):
return PartStudent.part_id.in_([part.id for part in userActiveSemester().parts]) return PartStudent.part.has(Part.semester == userActiveSemester())
def create_form(self, obj=None): def create_form(self, obj=None):
form = self.CreateForm form = self.CreateForm
@ -311,7 +311,7 @@ class PartStudentView(SecureAdminModelView):
def partStudentQueryFactory(): def partStudentQueryFactory():
return PartStudent.query.filter(PartStudent.part_id.in_([part.id for part in userActiveSemester().parts])) return PartStudent.query.filter(PartStudent.part.has(Part.semester == userActiveSemester()))
class GroupView(SecureAdminModelView): class GroupView(SecureAdminModelView):
@ -389,7 +389,7 @@ class ExperimentView(SecureAdminModelView):
def assistantQueryFactory(): def assistantQueryFactory():
return Assistant.query.filter(Assistant.user_id.in_([user.id for user in User.query.filter(User.active == True)])) return Assistant.query.filter(Assistant.user.has(User.active == True))
class SemesterExperimentView(SecureAdminModelView): class SemesterExperimentView(SecureAdminModelView):
@ -503,9 +503,7 @@ class GroupExperimentView(SecureAdminModelView):
column_filters = ["group", "semester_experiment.experiment", "appointments"] column_filters = ["group", "semester_experiment.experiment", "appointments"]
def queryFilter(self): def queryFilter(self):
return GroupExperiment.group_id.in_( return GroupExperiment.group.has(Group.semester == userActiveSemester())
[group.id for group in Group.query.filter(Group.semester == userActiveSemester())]
)
def customCreateModel(self, form): def customCreateModel(self, form):
return GroupExperiment.customInit(semester_experiment=form.semester_experiment.data, group=form.group.data) return GroupExperiment.customInit(semester_experiment=form.semester_experiment.data, group=form.group.data)
@ -530,14 +528,7 @@ class GroupExperimentView(SecureAdminModelView):
def groupExperimentQueryFactory(): def groupExperimentQueryFactory():
return GroupExperiment.query.filter( return GroupExperiment.query.filter(
GroupExperiment.semester_experiment_id.in_( GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
[
semesterExperiment.id
for semesterExperiment in SemesterExperiment.query.filter(
SemesterExperiment.semester == userActiveSemester()
)
]
)
) )
@ -570,8 +561,8 @@ class AppointmentView(SecureAdminModelView):
] ]
def queryFilter(self): def queryFilter(self):
return Appointment.group_experiment_id.in_( return Appointment.group_experiment.has(
groupExperiment.id for groupExperiment in groupExperimentQueryFactory() GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
) )
def customCreateModel(self, form): def customCreateModel(self, form):
@ -641,8 +632,8 @@ class ExperimentMarkView(SecureAdminModelView):
] ]
def queryFilter(self=None): def queryFilter(self=None):
return ExperimentMark.group_experiment_id.in_( return ExperimentMark.group_experiment.has(
groupExperiment.id for groupExperiment in groupExperimentQueryFactory() GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
) )
def checkForm(form): def checkForm(form):

View file

@ -32,18 +32,11 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
column_filters = ["group", "semester_experiment.experiment", "appointments"] column_filters = ["group", "semester_experiment.experiment", "appointments"]
def queryFilter1(self): def queryFilter1(self):
return GroupExperiment.group_id.in_( return GroupExperiment.group.has(Group.semester == userActiveSemester())
[group.id for group in Group.query.filter(Group.semester == userActiveSemester())]
)
def queryFilter2(self): def queryFilter2(self):
return GroupExperiment.semester_experiment_id.in_( return GroupExperiment.semester_experiment.has(
[ SemesterExperiment.assistants.any(Assistant.user == current_user)
semesterExperiment.id
for semesterExperiment in SemesterExperiment.query.filter(
SemesterExperiment.assistants.any(Assistant.id == current_user.assistant.id)
)
]
) )
def get_query(self): def get_query(self):