mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Improved filters
This commit is contained in:
parent
e4b29a37d6
commit
8333da3c91
2 changed files with 14 additions and 30 deletions
|
@ -118,7 +118,7 @@ class UserView(SecureAdminModelView):
|
|||
if model == current_user and not form.active.data:
|
||||
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()
|
||||
|
||||
UserView.flashPassword(password)
|
||||
|
@ -248,7 +248,7 @@ class StudentView(SecureAdminModelView):
|
|||
|
||||
|
||||
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():
|
||||
|
@ -294,7 +294,7 @@ class PartStudentView(SecureAdminModelView):
|
|||
column_filters = ["part", "student", "group"]
|
||||
|
||||
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):
|
||||
form = self.CreateForm
|
||||
|
@ -311,7 +311,7 @@ class PartStudentView(SecureAdminModelView):
|
|||
|
||||
|
||||
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):
|
||||
|
@ -389,7 +389,7 @@ class ExperimentView(SecureAdminModelView):
|
|||
|
||||
|
||||
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):
|
||||
|
@ -503,9 +503,7 @@ class GroupExperimentView(SecureAdminModelView):
|
|||
column_filters = ["group", "semester_experiment.experiment", "appointments"]
|
||||
|
||||
def queryFilter(self):
|
||||
return GroupExperiment.group_id.in_(
|
||||
[group.id for group in Group.query.filter(Group.semester == userActiveSemester())]
|
||||
)
|
||||
return GroupExperiment.group.has(Group.semester == userActiveSemester())
|
||||
|
||||
def customCreateModel(self, form):
|
||||
return GroupExperiment.customInit(semester_experiment=form.semester_experiment.data, group=form.group.data)
|
||||
|
@ -530,14 +528,7 @@ class GroupExperimentView(SecureAdminModelView):
|
|||
|
||||
def groupExperimentQueryFactory():
|
||||
return GroupExperiment.query.filter(
|
||||
GroupExperiment.semester_experiment_id.in_(
|
||||
[
|
||||
semesterExperiment.id
|
||||
for semesterExperiment in SemesterExperiment.query.filter(
|
||||
SemesterExperiment.semester == userActiveSemester()
|
||||
)
|
||||
]
|
||||
)
|
||||
GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
|
||||
)
|
||||
|
||||
|
||||
|
@ -570,8 +561,8 @@ class AppointmentView(SecureAdminModelView):
|
|||
]
|
||||
|
||||
def queryFilter(self):
|
||||
return Appointment.group_experiment_id.in_(
|
||||
groupExperiment.id for groupExperiment in groupExperimentQueryFactory()
|
||||
return Appointment.group_experiment.has(
|
||||
GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
|
||||
)
|
||||
|
||||
def customCreateModel(self, form):
|
||||
|
@ -641,8 +632,8 @@ class ExperimentMarkView(SecureAdminModelView):
|
|||
]
|
||||
|
||||
def queryFilter(self=None):
|
||||
return ExperimentMark.group_experiment_id.in_(
|
||||
groupExperiment.id for groupExperiment in groupExperimentQueryFactory()
|
||||
return ExperimentMark.group_experiment.has(
|
||||
GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
|
||||
)
|
||||
|
||||
def checkForm(form):
|
||||
|
|
|
@ -32,18 +32,11 @@ class AssistantGroupExperimentView(SecureAssistantModelView):
|
|||
column_filters = ["group", "semester_experiment.experiment", "appointments"]
|
||||
|
||||
def queryFilter1(self):
|
||||
return GroupExperiment.group_id.in_(
|
||||
[group.id for group in Group.query.filter(Group.semester == userActiveSemester())]
|
||||
)
|
||||
return GroupExperiment.group.has(Group.semester == userActiveSemester())
|
||||
|
||||
def queryFilter2(self):
|
||||
return GroupExperiment.semester_experiment_id.in_(
|
||||
[
|
||||
semesterExperiment.id
|
||||
for semesterExperiment in SemesterExperiment.query.filter(
|
||||
SemesterExperiment.assistants.any(Assistant.id == current_user.assistant.id)
|
||||
)
|
||||
]
|
||||
return GroupExperiment.semester_experiment.has(
|
||||
SemesterExperiment.assistants.any(Assistant.user == current_user)
|
||||
)
|
||||
|
||||
def get_query(self):
|
||||
|
|
Loading…
Reference in a new issue