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

Added AssistantGroupExperimentView

This commit is contained in:
Mo 2021-07-30 02:50:49 +02:00
parent 0be6b64b8a
commit f989cea879
3 changed files with 61 additions and 1 deletions

View file

@ -54,7 +54,7 @@ user_datastore = SQLAlchemyUserDatastore(db, models.User, models.Role)
Security(app, user_datastore) Security(app, user_datastore)
try: try:
from advlabdb import routes, modelViews from advlabdb import routes, adminModelViews, assistantModelViews
except Exception as ex: except Exception as ex:
print( print(
"\nYou are probably initializing the database with a script. If not, then you have to worry about not being able to import in __init__.py!\n" "\nYou are probably initializing the database with a script. If not, then you have to worry about not being able to import in __init__.py!\n"

View file

@ -0,0 +1,60 @@
from flask_security import current_user
from advlabdb import assistantSpace, db
from advlabdb.customClasses import SecureAssistantModelView
from advlabdb.models import (
Appointment,
Assistant,
Experiment,
ExperimentMark,
Group,
GroupExperiment,
Part,
SemesterExperiment,
PartStudent,
Role,
Semester,
Student,
User,
Program,
)
from advlabdb.utils import userActiveSemester
from advlabdb.exceptions import ModelViewException, DataBaseException
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"
)
)