mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +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):
|
||||||
|
def get_options(self, view):
|
||||||
semesters = Semester.query.order_by(Semester.id.desc())
|
semesters = Semester.query.order_by(Semester.id.desc())
|
||||||
return tuple((semester.id, semester.repr()) for semester in semesters)
|
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):
|
||||||
|
def get_options(self, view):
|
||||||
if has_request_context():
|
if has_request_context():
|
||||||
parts = Part.query.filter(Part.semester == userActiveSemester())
|
parts = Part.query.filter(Part.semester == userActiveSemester())
|
||||||
return tuple((part.id, f"{part.program.repr()}{part.number}") for part in parts)
|
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):
|
||||||
|
def get_options(self, view):
|
||||||
programs = Program.query
|
programs = Program.query
|
||||||
return tuple((program.id, program.repr()) for program in programs)
|
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,7 +860,8 @@ 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):
|
||||||
|
def get_options(self, view):
|
||||||
activeExperiments = Experiment.query.filter(Experiment.active == True)
|
activeExperiments = Experiment.query.filter(Experiment.active == True)
|
||||||
return tuple(
|
return tuple(
|
||||||
(
|
(
|
||||||
|
@ -884,10 +873,7 @@ def experimentFilterOptions():
|
||||||
|
|
||||||
|
|
||||||
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):
|
||||||
|
def get_options(self, view):
|
||||||
activeAssistants = assistantQueryFactory()
|
activeAssistants = assistantQueryFactory()
|
||||||
return tuple((assistant.id, assistant.repr()) for assistant in activeAssistants)
|
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,7 +1279,7 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
model.part_student.checkThenSetFinalPartMark()
|
model.part_student.checkThenSetFinalPartMark()
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
else:
|
|
||||||
# Nothing changed
|
# Nothing changed
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue