2021-07-30 00:50:49 +00:00
|
|
|
from flask_security import current_user
|
|
|
|
|
|
|
|
from advlabdb import assistantSpace, db
|
|
|
|
from advlabdb.customClasses import SecureAssistantModelView
|
2021-07-30 12:20:54 +00:00
|
|
|
from advlabdb.exceptions import DataBaseException, ModelViewException
|
2021-07-30 00:50:49 +00:00
|
|
|
from advlabdb.models import (
|
|
|
|
Appointment,
|
|
|
|
Assistant,
|
|
|
|
Experiment,
|
|
|
|
ExperimentMark,
|
|
|
|
Group,
|
|
|
|
GroupExperiment,
|
|
|
|
Part,
|
|
|
|
PartStudent,
|
2021-07-30 12:20:54 +00:00
|
|
|
Program,
|
2021-07-30 00:50:49 +00:00
|
|
|
Role,
|
|
|
|
Semester,
|
2021-07-30 12:20:54 +00:00
|
|
|
SemesterExperiment,
|
2021-07-30 00:50:49 +00:00
|
|
|
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):
|
2021-07-30 13:14:35 +00:00
|
|
|
return GroupExperiment.group.has(Group.semester == userActiveSemester())
|
2021-07-30 00:50:49 +00:00
|
|
|
|
|
|
|
def queryFilter2(self):
|
2021-07-30 13:14:35 +00:00
|
|
|
return GroupExperiment.semester_experiment.has(
|
|
|
|
SemesterExperiment.assistants.any(Assistant.user == current_user)
|
2021-07-30 00:50:49 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
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"
|
|
|
|
)
|
|
|
|
)
|