mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
60 lines
1.7 KiB
Python
60 lines
1.7 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_id.in_(
|
|
[group.id for group in Group.query.filter(Group.semester == userActiveSemester())]
|
|
)
|
|
|
|
def queryFilter2(self):
|
|
return GroupExperiment.semester_experiment_id.in_(
|
|
[
|
|
semesterExperiment.id
|
|
for semesterExperiment in SemesterExperiment.query.filter(
|
|
SemesterExperiment.assistants.any(Assistant.id == current_user.assistant.id)
|
|
)
|
|
]
|
|
)
|
|
|
|
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"
|
|
)
|
|
)
|