1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Added Appointment and ExperimentMark views in assistantSpace

This commit is contained in:
Mo 2021-07-30 23:50:10 +02:00
parent c0ffa136f7
commit b9621345d7
3 changed files with 64 additions and 29 deletions

View file

@ -572,12 +572,10 @@ class AppointmentView(SecureAdminModelView):
)
def update_model(self, form, model):
if not form.date or not form.special: # For editables
return super().update_model(form, model)
try:
if not form.date:
model.customUpdateSpecial(form.special.data)
elif not form.special:
model.customUpdateDate(form.date.data)
else:
model.customUpdate(form.date.data, form.special.data, form.assistant.data, form.group_experiment.data)
self.on_model_change(form, model, False)

View file

@ -1,4 +1,10 @@
from flask import flash
from flask_security import current_user
from wtforms import BooleanField, Form, RadioField, SelectField, TextField
from wtforms.fields.html5 import DateField
from flask_admin.contrib.sqla.fields import QuerySelectField, QuerySelectMultipleField
from sqlalchemy import and_
from wtforms.validators import NumberRange
from advlabdb import assistantSpace, db
from advlabdb.customClasses import SecureAssistantModelView
@ -22,32 +28,69 @@ from advlabdb.models import (
from advlabdb.utils import userActiveSemester
class AssistantGroupExperimentView(SecureAssistantModelView):
class AssistantAppointmentView(SecureAssistantModelView):
can_export = False
can_set_page_size = False
can_create = False
can_edit = False
can_delete = False
can_edit = False
column_display_actions = False
column_list = ["group", "semester_experiment", "appointments", "experiment_marks"]
column_filters = ["group", "semester_experiment.experiment", "appointments"]
column_list = ["date", "special", "group_experiment"]
column_editable_list = ["date", "special"]
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 queryFilter(self):
return and_(
Appointment.group_experiment.has(
GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
),
Appointment.assistant == current_user.assistant,
)
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())
class AssistantExperimentMarkView(SecureAssistantModelView):
can_export = False
can_set_page_size = False
can_create = False
can_delete = False
can_edit = False
column_display_actions = False
column_editable_list = ["oral_mark", "protocol_mark"]
form_args = {
"oral_mark": {"validators": [NumberRange(0, 15)]},
"protocol_mark": {"validators": [NumberRange(0, 15)]},
}
column_default_sort = [("oral_mark", False), ("protocol_mark", False)]
def queryFilter(self):
return ExperimentMark.group_experiment.has(
GroupExperiment.semester_experiment.has(
and_(
SemesterExperiment.semester == userActiveSemester(),
SemesterExperiment.assistants.any(Assistant.user == current_user),
)
)
)
def after_model_change(self, form, model, is_created):
if model.oral_mark or model.protocol_mark:
try:
model.assistant = current_user.assistant
self.session.commit()
except Exception as ex:
flash(str(ex), "error")
self.session.rollback()
assistantSpace.add_view(
AssistantGroupExperimentView(
GroupExperiment, db.session, endpoint="assistant_groupexperiment", url="groupexperiment"
)
AssistantAppointmentView(Appointment, db.session, endpoint="assistant_appointment", url="appointment")
)
assistantSpace.add_view(
AssistantExperimentMarkView(ExperimentMark, db.session, endpoint="assistant_experimentmark", url="experimentmark")
)

View file

@ -313,12 +313,6 @@ class Appointment(db.Model):
self.assistant = assistant
self.group_experiment = group_experiment
def customUpdateDate(self, date):
self.date = date
def customUpdateSpecial(self, special):
self.special = special
def repr(self):
return f"{self.date} {self.group_experiment.repr()}"