mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-12-20 23:41:20 +00:00
Replace all .has()
This commit is contained in:
parent
d7886eb773
commit
91826cc98d
1 changed files with 42 additions and 57 deletions
|
@ -78,7 +78,7 @@ class SemesterRowFilter(FilterEqual):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
return tuple()
|
return tuple()
|
||||||
|
|
||||||
semesters = Semester.query.order_by(Semester.id.desc())
|
semesters = sortedSemestersStartingWithNewest()
|
||||||
return tuple((semester.id, semester.repr()) for semester in semesters)
|
return tuple((semester.id, semester.repr()) for semester in semesters)
|
||||||
|
|
||||||
|
|
||||||
|
@ -474,7 +474,7 @@ class PartRowFilter(FilterEqual):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
return tuple()
|
return tuple()
|
||||||
|
|
||||||
parts = Part.query.filter(Part.semester == current_user.active_semester)
|
parts = db.execute(select(Part).where(Part.semester == current_user.active_semester)).scalars()
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -576,7 +576,7 @@ class ProgramRowFilter(FilterEqual):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
return tuple()
|
return tuple()
|
||||||
|
|
||||||
programs = Program.query
|
programs = db.execute(select(Program)).scalars()
|
||||||
return tuple((program.id, program.repr()) for program in programs)
|
return tuple((program.id, program.repr()) for program in programs)
|
||||||
|
|
||||||
|
|
||||||
|
@ -596,7 +596,7 @@ class GroupView(SecureAdminModelView):
|
||||||
def query_factory():
|
def query_factory():
|
||||||
return partStudentQueryFactory().where(
|
return partStudentQueryFactory().where(
|
||||||
or_(
|
or_(
|
||||||
and_(PartStudent.group == None, PartStudent.part.has(Part.program == group.program)),
|
and_(PartStudent.group == None, Part.program == group.program),
|
||||||
PartStudent.group == group,
|
PartStudent.group == group,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -702,13 +702,13 @@ class ExperimentView(SecureAdminModelView):
|
||||||
|
|
||||||
|
|
||||||
def assistantQueryFactory():
|
def assistantQueryFactory():
|
||||||
return Assistant.query.filter(Assistant.user.has(User.active == True))
|
return Assistant.query.join(User).where(User.active == True)
|
||||||
|
|
||||||
|
|
||||||
class SemesterExperimentView(SecureAdminModelView):
|
class SemesterExperimentView(SecureAdminModelView):
|
||||||
class ProgramFilter(ProgramRowFilter):
|
class ProgramFilter(ProgramRowFilter):
|
||||||
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.join(Experiment).where(Experiment.program_id == int(value))
|
||||||
|
|
||||||
class ExperimentEndpointLinkRowAction(CustomIdEndpointLinkRowAction):
|
class ExperimentEndpointLinkRowAction(CustomIdEndpointLinkRowAction):
|
||||||
def customId(self, row):
|
def customId(self, row):
|
||||||
|
@ -823,10 +823,11 @@ class SemesterExperimentView(SecureAdminModelView):
|
||||||
def userHasRoleFilterFactory(column, role_name):
|
def userHasRoleFilterFactory(column, role_name):
|
||||||
class UserHasRoleFilter(BooleanEqualFilter):
|
class UserHasRoleFilter(BooleanEqualFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
|
query = query.join(User)
|
||||||
if bool(int(value)): # value is string "0" or "1"
|
if bool(int(value)): # value is string "0" or "1"
|
||||||
return query.filter(self.column.user.has(User.roles.any(Role.name == role_name)))
|
return query.join(User.roles).where(Role.name == role_name)
|
||||||
else:
|
else:
|
||||||
return query.filter(self.column.user.has(not_(User.roles.any(Role.name == role_name))))
|
return query.where(not_(User.roles.any(Role.name == role_name)))
|
||||||
|
|
||||||
return UserHasRoleFilter(column, f"Currently has {role_name} role")
|
return UserHasRoleFilter(column, f"Currently has {role_name} role")
|
||||||
|
|
||||||
|
@ -930,7 +931,7 @@ class ExperimentRowFilter(FilterEqual):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
return tuple()
|
return tuple()
|
||||||
|
|
||||||
activeExperiments = Experiment.query.filter(Experiment.active == True)
|
activeExperiments = db.execute(select(Experiment).where(Experiment.active == True)).scalars()
|
||||||
return tuple(
|
return tuple(
|
||||||
(
|
(
|
||||||
f"{activeExperiment.number},{activeExperiment.program_id}",
|
f"{activeExperiment.number},{activeExperiment.program_id}",
|
||||||
|
@ -939,21 +940,23 @@ class ExperimentRowFilter(FilterEqual):
|
||||||
for activeExperiment in activeExperiments
|
for activeExperiment in activeExperiments
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_values(value):
|
||||||
|
values = value.split(",")
|
||||||
|
experimentNumber = int(values[0])
|
||||||
|
programId = int(values[1])
|
||||||
|
|
||||||
|
return (experimentNumber, programId)
|
||||||
|
|
||||||
|
|
||||||
class GroupExperimentView(SecureAdminModelView):
|
class GroupExperimentView(SecureAdminModelView):
|
||||||
class ExperimentFilter(ExperimentRowFilter):
|
class ExperimentFilter(ExperimentRowFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
values = value.split(",")
|
experimentNumber, programId = ExperimentRowFilter.get_values(value)
|
||||||
experimentNumber = int(values[0])
|
|
||||||
programId = int(values[1])
|
|
||||||
|
|
||||||
return query.filter(
|
return (
|
||||||
self.column.semester_experiment.has(
|
query.join(SemesterExperiment)
|
||||||
SemesterExperiment.experiment.has(Experiment.program_id == programId)
|
.join(Experiment)
|
||||||
),
|
.where(Experiment.program_id == programId, Experiment.number == experimentNumber)
|
||||||
self.column.semester_experiment.has(
|
|
||||||
SemesterExperiment.experiment.has(Experiment.number == experimentNumber)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class GroupEndpointLinkRowAction(CustomIdEndpointLinkRowAction):
|
class GroupEndpointLinkRowAction(CustomIdEndpointLinkRowAction):
|
||||||
|
@ -1068,8 +1071,8 @@ class GroupExperimentView(SecureAdminModelView):
|
||||||
|
|
||||||
|
|
||||||
def groupExperimentQueryFactory():
|
def groupExperimentQueryFactory():
|
||||||
return GroupExperiment.query.filter(
|
return GroupExperiment.query.join(SemesterExperiment).where(
|
||||||
GroupExperiment.semester_experiment.has(SemesterExperiment.semester == current_user.active_semester)
|
SemesterExperiment.semester == current_user.active_semester
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1085,21 +1088,13 @@ class AssistantRowFilter(FilterEqual):
|
||||||
class AppointmentView(SecureAdminModelView):
|
class AppointmentView(SecureAdminModelView):
|
||||||
class ExperimentFilter(ExperimentRowFilter):
|
class ExperimentFilter(ExperimentRowFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
values = value.split(",")
|
experimentNumber, programId = ExperimentRowFilter.get_values(value)
|
||||||
experimentNumber = int(values[0])
|
|
||||||
programId = int(values[1])
|
|
||||||
|
|
||||||
return query.filter(
|
return (
|
||||||
self.column.group_experiment.has(
|
query.join(GroupExperiment)
|
||||||
GroupExperiment.semester_experiment.has(
|
.join(SemesterExperiment)
|
||||||
SemesterExperiment.experiment.has(Experiment.program_id == programId)
|
.join(Experiment)
|
||||||
)
|
.where(Experiment.program_id == programId, Experiment.number == experimentNumber)
|
||||||
),
|
|
||||||
self.column.group_experiment.has(
|
|
||||||
GroupExperiment.semester_experiment.has(
|
|
||||||
SemesterExperiment.experiment.has(Experiment.number == experimentNumber)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class AssistantFilter(AssistantRowFilter):
|
class AssistantFilter(AssistantRowFilter):
|
||||||
|
@ -1205,7 +1200,7 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
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.join(PartStudent).where(PartStudent.student_id == int(value))
|
||||||
|
|
||||||
class AssistantFilter(AssistantRowFilter):
|
class AssistantFilter(AssistantRowFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
|
@ -1216,7 +1211,7 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
if not has_request_context():
|
if not has_request_context():
|
||||||
return tuple()
|
return tuple()
|
||||||
|
|
||||||
admins = Admin.query.filter(Admin.user.has(User.active == True))
|
admins = db.execute(select(Admin).join(User).where(User.active == True)).scalars()
|
||||||
return tuple((admin.id, admin.repr()) for admin in admins)
|
return tuple((admin.id, admin.repr()) for admin in admins)
|
||||||
|
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
|
@ -1224,37 +1219,27 @@ class ExperimentMarkView(SecureAdminModelView):
|
||||||
|
|
||||||
class ExperimentFilter(ExperimentRowFilter):
|
class ExperimentFilter(ExperimentRowFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
values = value.split(",")
|
experimentNumber, programId = ExperimentRowFilter.get_values(value)
|
||||||
experimentNumber = int(values[0])
|
|
||||||
programId = int(values[1])
|
|
||||||
|
|
||||||
return query.filter(
|
return (
|
||||||
self.column.group_experiment.has(
|
query.join(GroupExperiment)
|
||||||
GroupExperiment.semester_experiment.has(
|
.join(SemesterExperiment)
|
||||||
SemesterExperiment.experiment.has(Experiment.program_id == programId)
|
.join(Experiment)
|
||||||
)
|
.where(Experiment.program_id == programId, Experiment.number == experimentNumber)
|
||||||
),
|
|
||||||
self.column.group_experiment.has(
|
|
||||||
GroupExperiment.semester_experiment.has(
|
|
||||||
SemesterExperiment.experiment.has(Experiment.number == experimentNumber)
|
|
||||||
)
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class ProgramFilter(ProgramRowFilter):
|
class ProgramFilter(ProgramRowFilter):
|
||||||
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.join(PartStudent).join(Part).where(Part.program_id == int(value))
|
||||||
|
|
||||||
class PartFilter(PartRowFilter):
|
class PartFilter(PartRowFilter):
|
||||||
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.join(PartStudent).where(PartStudent.part_id == int(value))
|
||||||
|
|
||||||
class SemesterFilter(SemesterRowFilter):
|
class SemesterFilter(SemesterRowFilter):
|
||||||
def apply(self, query, value, alias=None):
|
def apply(self, query, value, alias=None):
|
||||||
return query.filter(
|
return (
|
||||||
self.column.group_experiment.has(
|
query.join(GroupExperiment).join(SemesterExperiment).where(SemesterExperiment.semester_id == int(value))
|
||||||
GroupExperiment.semester_experiment.has(SemesterExperiment.semester_id == int(value))
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
class PartStudentEndpointLinkRowAction(CustomIdEndpointLinkRowAction):
|
class PartStudentEndpointLinkRowAction(CustomIdEndpointLinkRowAction):
|
||||||
|
|
Loading…
Reference in a new issue