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

Fix some problems with app context

This commit is contained in:
Mo 2022-05-07 23:53:47 +02:00
parent b9d5aad18d
commit 3fd804d175

View file

@ -76,6 +76,9 @@ def semesterExperimentQueryFactory():
class SemesterRowFilter(FilterEqual):
def get_options(self, view):
if not has_request_context():
return tuple()
semesters = Semester.query.order_by(Semester.id.desc())
return tuple((semester.id, semester.repr()) for semester in semesters)
@ -470,9 +473,11 @@ def groupQueryFactory():
class PartRowFilter(FilterEqual):
def get_options(self, view):
if has_request_context():
parts = Part.query.filter(Part.semester == userActiveSemester())
return tuple((part.id, f"{part.program.repr()}{part.number}") for part in parts)
if not has_request_context():
return tuple()
parts = Part.query.filter(Part.semester == userActiveSemester())
return tuple((part.id, f"{part.program.repr()}{part.number}") for part in parts)
class PartStudentView(SecureAdminModelView):
@ -570,6 +575,9 @@ def partStudentQueryFactory():
class ProgramRowFilter(FilterEqual):
def get_options(self, view):
if not has_request_context():
return tuple()
programs = Program.query
return tuple((program.id, program.repr()) for program in programs)
@ -904,6 +912,9 @@ assistantBlankText = "Auto assign if experiment has only one assistant"
class ExperimentRowFilter(FilterEqual):
def get_options(self, view):
if not has_request_context():
return tuple()
activeExperiments = Experiment.query.filter(Experiment.active == True)
return tuple(
(
@ -1052,6 +1063,9 @@ def groupExperimentQueryFactory():
class AssistantRowFilter(FilterEqual):
def get_options(self, view):
if not has_request_context():
return tuple()
activeAssistants = assistantQueryFactory()
return tuple((assistant.id, assistant.repr()) for assistant in activeAssistants)
@ -1187,6 +1201,9 @@ class ExperimentMarkView(SecureAdminModelView):
class AdminFilter(FilterEqual):
def get_options(self, view):
if not has_request_context():
return tuple()
admins = Admin.query.filter(Admin.user.has(User.active == True))
return tuple((admin.id, admin.repr()) for admin in admins)