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

145 lines
4.5 KiB
Python
Raw Normal View History

from flask import flash
from flask_admin.contrib.sqla.fields import QuerySelectField, QuerySelectMultipleField
2021-07-30 00:50:49 +00:00
from flask_security import current_user
from sqlalchemy import and_
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
from wtforms.fields.html5 import DateField
from wtforms.validators import NumberRange
2021-07-30 00:50:49 +00:00
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 initActiveSemesterMenuLinks, userActiveSemester
2021-07-30 00:50:49 +00:00
class AssistantAppointmentView(SecureAssistantModelView):
can_export = False
can_set_page_size = False
2021-07-30 00:50:49 +00:00
can_create = False
can_delete = False
2021-07-30 00:50:49 +00:00
can_edit = False
column_display_actions = False
2021-07-31 22:41:21 +00:00
column_list = [
"date",
"special",
"group_experiment.semester_experiment.experiment",
"group_experiment.group",
"group_experiment.group.part_students",
]
column_labels = {
"group_experiment.semester_experiment.experiment": "Experiment",
"group_experiment.group": "Group",
"group_experiment.group.part_students": "Students",
}
column_editable_list = ["date"]
def queryFilter(self):
return and_(
Appointment.group_experiment.has(
GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
),
Appointment.assistant == current_user.assistant,
)
class AssistantExperimentMarkView(SecureAssistantModelView):
can_export = False
can_set_page_size = False
can_create = False
2021-07-30 00:50:49 +00:00
can_delete = False
can_edit = False
2021-07-30 00:50:49 +00:00
column_display_actions = False
2021-07-31 22:41:21 +00:00
column_list = [
"oral_mark",
"protocol_mark",
"group_experiment.semester_experiment.experiment",
"part_student.student.first_name",
"part_student.student.last_name",
"part_student.group",
"part_student.student.uni_email",
"part_student.student.contact_email",
"part_student.part",
"assistant",
"edited_by_admin",
]
column_labels = {
"group_experiment.semester_experiment.experiment": "Experiment",
"part_student.student.first_name": "First Name",
"part_student.student.last_name": "Last Name",
"part_student.group": "Group",
"part_student.student.uni_email": "Uni Email",
"part_student.student.contact_email": "Contact Email",
"part_student.part": "Part",
}
column_descriptions = {
"oral_mark": "Between 0 and 15",
"protocol_mark": "Between 0 and 15",
"part_student.student.contact_email": "The preferred contact email address if entered by the student",
"assistant": "The assistant who assigned the mark",
"edited_by_admin": "If the mark was edited by an admin",
}
column_editable_list = ["oral_mark", "protocol_mark"]
form_args = {
"oral_mark": {"validators": [NumberRange(0, 15)]},
"protocol_mark": {"validators": [NumberRange(0, 15)]},
}
2021-07-30 00:50:49 +00:00
column_default_sort = [("oral_mark", False), ("protocol_mark", False)]
2021-07-30 00:50:49 +00:00
def queryFilter(self):
return ExperimentMark.group_experiment.has(
GroupExperiment.semester_experiment.has(
and_(
SemesterExperiment.semester == userActiveSemester(),
SemesterExperiment.assistants.any(Assistant.user == current_user),
)
)
2021-07-30 00:50:49 +00:00
)
def update_model(self, form, model):
if (form.oral_mark and form.oral_mark.data != model.oral_mark) or (
form.protocol_mark and form.protocol_mark.data != model.protocol_mark
):
model.assistant = current_user.assistant
2021-07-30 00:50:49 +00:00
ret = super().update_model(form, model)
2021-07-30 00:50:49 +00:00
model.part_student.checkThenSetFinalPartMark()
return ret
else:
# Nothing changed
return True
2021-07-30 00:50:49 +00:00
assistantSpace.add_view(
AssistantAppointmentView(Appointment, db.session, endpoint="assistant_appointment", url="appointment")
)
2021-07-30 00:50:49 +00:00
assistantSpace.add_view(
AssistantExperimentMarkView(ExperimentMark, db.session, endpoint="assistant_experimentmark", url="experimentmark")
2021-07-30 00:50:49 +00:00
)
initActiveSemesterMenuLinks(assistantSpace)