1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +00:00
AdvLabDB/advlabdb/assistantModelViews.py
2021-07-30 15:14:35 +02:00

53 lines
1.5 KiB
Python

from flask_security import current_user
from advlabdb import assistantSpace, db
from advlabdb.customClasses import SecureAssistantModelView
from advlabdb.exceptions import DataBaseException, ModelViewException
from advlabdb.models import (
Appointment,
Assistant,
Experiment,
ExperimentMark,
Group,
GroupExperiment,
Part,
PartStudent,
Program,
Role,
Semester,
SemesterExperiment,
Student,
User,
)
from advlabdb.utils import userActiveSemester
class AssistantGroupExperimentView(SecureAssistantModelView):
can_create = False
can_edit = False
can_delete = False
column_display_actions = False
column_list = ["group", "semester_experiment", "appointments", "experiment_marks"]
column_filters = ["group", "semester_experiment.experiment", "appointments"]
def queryFilter1(self):
return GroupExperiment.group.has(Group.semester == userActiveSemester())
def queryFilter2(self):
return GroupExperiment.semester_experiment.has(
SemesterExperiment.assistants.any(Assistant.user == current_user)
)
def get_query(self):
return super().get_query().filter(self.queryFilter1()).filter(self.queryFilter2())
def get_count_query(self):
return super().get_count_query().filter(self.queryFilter1()).filter(self.queryFilter2())
assistantSpace.add_view(
AssistantGroupExperimentView(
GroupExperiment, db.session, endpoint="assistant_groupexperiment", url="groupexperiment"
)
)