mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Add row filters for deduplication
This commit is contained in:
parent
99703439a3
commit
6f30f90b64
1 changed files with 42 additions and 76 deletions
|
@ -74,16 +74,14 @@ def semesterExperimentQueryFactory():
|
||||||
return SemesterExperiment.query.filter(SemesterExperiment.semester == userActiveSemester())
|
return SemesterExperiment.query.filter(SemesterExperiment.semester == userActiveSemester())
|
||||||
|
|
||||||
|
|
||||||
def semesterFilterOptions():
|
class SemesterRowFilter(FilterEqual):
|
||||||
semesters = Semester.query.order_by(Semester.id.desc())
|
def get_options(self, view):
|
||||||
return tuple((semester.id, semester.repr()) for semester in semesters)
|
semesters = Semester.query.order_by(Semester.id.desc())
|
||||||
|
return tuple((semester.id, semester.repr()) for semester in semesters)
|
||||||
|
|
||||||
|
|
||||||
class UserView(SecureAdminModelView):
|
class UserView(SecureAdminModelView):
|
||||||
class SemesterFilter(FilterEqual):
|
class SemesterFilter(SemesterRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return semesterFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.active_semester_id == int(value))
|
return query.filter(self.column.active_semester_id == int(value))
|
||||||
|
|
||||||
|
@ -435,17 +433,15 @@ def groupQueryFactory():
|
||||||
return Group.query.filter(Group.semester == userActiveSemester())
|
return Group.query.filter(Group.semester == userActiveSemester())
|
||||||
|
|
||||||
|
|
||||||
def partFilterOptions():
|
class PartRowFilter(FilterEqual):
|
||||||
if has_request_context():
|
def get_options(self, view):
|
||||||
parts = Part.query.filter(Part.semester == userActiveSemester())
|
if has_request_context():
|
||||||
return tuple((part.id, f"{part.program.repr()}{part.number}") for part in parts)
|
parts = Part.query.filter(Part.semester == userActiveSemester())
|
||||||
|
return tuple((part.id, f"{part.program.repr()}{part.number}") for part in parts)
|
||||||
|
|
||||||
|
|
||||||
class PartStudentView(SecureAdminModelView):
|
class PartStudentView(SecureAdminModelView):
|
||||||
class PartFilter(FilterEqual):
|
class PartFilter(PartRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return partFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.part_id == int(value))
|
return query.filter(self.column.part_id == int(value))
|
||||||
|
|
||||||
|
@ -537,16 +533,14 @@ def partStudentQueryFactory():
|
||||||
return PartStudent.query.filter(PartStudent.part.has(Part.semester == userActiveSemester()))
|
return PartStudent.query.filter(PartStudent.part.has(Part.semester == userActiveSemester()))
|
||||||
|
|
||||||
|
|
||||||
def programFilterOptions():
|
class ProgramRowFilter(FilterEqual):
|
||||||
programs = Program.query
|
def get_options(self, view):
|
||||||
return tuple((program.id, program.repr()) for program in programs)
|
programs = Program.query
|
||||||
|
return tuple((program.id, program.repr()) for program in programs)
|
||||||
|
|
||||||
|
|
||||||
class GroupView(SecureAdminModelView):
|
class GroupView(SecureAdminModelView):
|
||||||
class ProgramFilter(FilterEqual):
|
class ProgramFilter(ProgramRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return programFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.program_id == int(value))
|
return query.filter(self.column.program_id == int(value))
|
||||||
|
|
||||||
|
@ -608,10 +602,7 @@ class GroupView(SecureAdminModelView):
|
||||||
|
|
||||||
|
|
||||||
class ExperimentView(SecureAdminModelView):
|
class ExperimentView(SecureAdminModelView):
|
||||||
class ProgramFilter(FilterEqual):
|
class ProgramFilter(ProgramRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return programFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.program_id == int(value))
|
return query.filter(self.column.program_id == int(value))
|
||||||
|
|
||||||
|
@ -670,10 +661,7 @@ def assistantQueryFactory():
|
||||||
|
|
||||||
|
|
||||||
class SemesterExperimentView(SecureAdminModelView):
|
class SemesterExperimentView(SecureAdminModelView):
|
||||||
class ProgramFilter(FilterEqual):
|
class ProgramFilter(ProgramRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return programFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.experiment.has(Experiment.program_id == int(value)))
|
return query.filter(self.column.experiment.has(Experiment.program_id == int(value)))
|
||||||
|
|
||||||
|
@ -872,22 +860,20 @@ class AdminView(SecureAdminModelView):
|
||||||
assistantBlankText = "Auto assign if experiment has only one assistant"
|
assistantBlankText = "Auto assign if experiment has only one assistant"
|
||||||
|
|
||||||
|
|
||||||
def experimentFilterOptions():
|
class ExperimentRowFilter(FilterEqual):
|
||||||
activeExperiments = Experiment.query.filter(Experiment.active == True)
|
def get_options(self, view):
|
||||||
return tuple(
|
activeExperiments = Experiment.query.filter(Experiment.active == True)
|
||||||
(
|
return tuple(
|
||||||
f"{activeExperiment.number},{activeExperiment.program_id}",
|
(
|
||||||
f"{activeExperiment.number} {activeExperiment.program.repr()}",
|
f"{activeExperiment.number},{activeExperiment.program_id}",
|
||||||
|
f"{activeExperiment.number} {activeExperiment.program.repr()}",
|
||||||
|
)
|
||||||
|
for activeExperiment in activeExperiments
|
||||||
)
|
)
|
||||||
for activeExperiment in activeExperiments
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class GroupExperimentView(SecureAdminModelView):
|
class GroupExperimentView(SecureAdminModelView):
|
||||||
class ExperimentFilter(FilterEqual):
|
class ExperimentFilter(ExperimentRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return experimentFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
values = value.split(",")
|
values = value.split(",")
|
||||||
experimentNumber = int(values[0])
|
experimentNumber = int(values[0])
|
||||||
|
@ -1014,16 +1000,14 @@ def groupExperimentQueryFactory():
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def assistantFilterOptions():
|
class AssistantRowFilter(FilterEqual):
|
||||||
activeAssistants = assistantQueryFactory()
|
def get_options(self, view):
|
||||||
return tuple((assistant.id, assistant.repr()) for assistant in activeAssistants)
|
activeAssistants = assistantQueryFactory()
|
||||||
|
return tuple((assistant.id, assistant.repr()) for assistant in activeAssistants)
|
||||||
|
|
||||||
|
|
||||||
class AppointmentView(SecureAdminModelView):
|
class AppointmentView(SecureAdminModelView):
|
||||||
class ExperimentFilter(FilterEqual):
|
class ExperimentFilter(ExperimentRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return experimentFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
values = value.split(",")
|
values = value.split(",")
|
||||||
experimentNumber = int(values[0])
|
experimentNumber = int(values[0])
|
||||||
|
@ -1042,10 +1026,7 @@ class AppointmentView(SecureAdminModelView):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
class AssistantFilter(FilterEqual):
|
class AssistantFilter(AssistantRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return assistantFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.assistant_id == int(value))
|
return query.filter(self.column.assistant_id == int(value))
|
||||||
|
|
||||||
|
@ -1144,10 +1125,7 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.part_student.has(PartStudent.student_id == int(value)))
|
return query.filter(self.column.part_student.has(PartStudent.student_id == int(value)))
|
||||||
|
|
||||||
class AssistantFilter(FilterEqual):
|
class AssistantFilter(AssistantRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return assistantFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.assistant_id == int(value))
|
return query.filter(self.column.assistant_id == int(value))
|
||||||
|
|
||||||
|
@ -1159,10 +1137,7 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.admin_id == int(value))
|
return query.filter(self.column.admin_id == int(value))
|
||||||
|
|
||||||
class ExperimentFilter(FilterEqual):
|
class ExperimentFilter(ExperimentRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return experimentFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
values = value.split(",")
|
values = value.split(",")
|
||||||
experimentNumber = int(values[0])
|
experimentNumber = int(values[0])
|
||||||
|
@ -1181,24 +1156,15 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
class ProgramFilter(FilterEqual):
|
class ProgramFilter(ProgramRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return programFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.part_student.has(PartStudent.part.has(Part.program_id == int(value))))
|
return query.filter(self.column.part_student.has(PartStudent.part.has(Part.program_id == int(value))))
|
||||||
|
|
||||||
class PartFilter(FilterEqual):
|
class PartFilter(PartRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return partFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(self.column.part_student.has(PartStudent.part_id == int(value)))
|
return query.filter(self.column.part_student.has(PartStudent.part_id == int(value)))
|
||||||
|
|
||||||
class SemesterFilter(FilterEqual):
|
class SemesterFilter(SemesterRowFilter):
|
||||||
def get_options(self, view):
|
|
||||||
return semesterFilterOptions()
|
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(
|
return query.filter(
|
||||||
self.column.group_experiment.has(
|
self.column.group_experiment.has(
|
||||||
|
@ -1313,9 +1279,9 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
model.part_student.checkThenSetFinalPartMark()
|
model.part_student.checkThenSetFinalPartMark()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
else:
|
|
||||||
# Nothing changed
|
# Nothing changed
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class ProgramView(SecureAdminModelView):
|
class ProgramView(SecureAdminModelView):
|
||||||
|
|
Loading…
Reference in a new issue