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:
parent
c0ffa136f7
commit
b9621345d7
3 changed files with 64 additions and 29 deletions
|
@ -572,12 +572,10 @@ class AppointmentView(SecureAdminModelView):
|
||||||
)
|
)
|
||||||
|
|
||||||
def update_model(self, form, model):
|
def update_model(self, form, model):
|
||||||
|
if not form.date or not form.special: # For editables
|
||||||
|
return super().update_model(form, model)
|
||||||
|
|
||||||
try:
|
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)
|
model.customUpdate(form.date.data, form.special.data, form.assistant.data, form.group_experiment.data)
|
||||||
|
|
||||||
self.on_model_change(form, model, False)
|
self.on_model_change(form, model, False)
|
||||||
|
|
|
@ -1,4 +1,10 @@
|
||||||
|
from flask import flash
|
||||||
from flask_security import current_user
|
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 import assistantSpace, db
|
||||||
from advlabdb.customClasses import SecureAssistantModelView
|
from advlabdb.customClasses import SecureAssistantModelView
|
||||||
|
@ -22,32 +28,69 @@ from advlabdb.models import (
|
||||||
from advlabdb.utils import userActiveSemester
|
from advlabdb.utils import userActiveSemester
|
||||||
|
|
||||||
|
|
||||||
class AssistantGroupExperimentView(SecureAssistantModelView):
|
class AssistantAppointmentView(SecureAssistantModelView):
|
||||||
|
can_export = False
|
||||||
|
can_set_page_size = False
|
||||||
|
|
||||||
can_create = False
|
can_create = False
|
||||||
can_edit = False
|
|
||||||
can_delete = False
|
can_delete = False
|
||||||
|
can_edit = False
|
||||||
column_display_actions = False
|
column_display_actions = False
|
||||||
|
|
||||||
column_list = ["group", "semester_experiment", "appointments", "experiment_marks"]
|
column_list = ["date", "special", "group_experiment"]
|
||||||
column_filters = ["group", "semester_experiment.experiment", "appointments"]
|
column_editable_list = ["date", "special"]
|
||||||
|
|
||||||
def queryFilter1(self):
|
def queryFilter(self):
|
||||||
return GroupExperiment.group.has(Group.semester == userActiveSemester())
|
return and_(
|
||||||
|
Appointment.group_experiment.has(
|
||||||
def queryFilter2(self):
|
GroupExperiment.semester_experiment.has(SemesterExperiment.semester == userActiveSemester())
|
||||||
return GroupExperiment.semester_experiment.has(
|
),
|
||||||
SemesterExperiment.assistants.any(Assistant.user == current_user)
|
Appointment.assistant == current_user.assistant,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_query(self):
|
|
||||||
return super().get_query().filter(self.queryFilter1()).filter(self.queryFilter2())
|
|
||||||
|
|
||||||
def get_count_query(self):
|
class AssistantExperimentMarkView(SecureAssistantModelView):
|
||||||
return super().get_count_query().filter(self.queryFilter1()).filter(self.queryFilter2())
|
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(
|
assistantSpace.add_view(
|
||||||
AssistantGroupExperimentView(
|
AssistantAppointmentView(Appointment, db.session, endpoint="assistant_appointment", url="appointment")
|
||||||
GroupExperiment, db.session, endpoint="assistant_groupexperiment", url="groupexperiment"
|
)
|
||||||
)
|
assistantSpace.add_view(
|
||||||
|
AssistantExperimentMarkView(ExperimentMark, db.session, endpoint="assistant_experimentmark", url="experimentmark")
|
||||||
)
|
)
|
||||||
|
|
|
@ -313,12 +313,6 @@ class Appointment(db.Model):
|
||||||
self.assistant = assistant
|
self.assistant = assistant
|
||||||
self.group_experiment = group_experiment
|
self.group_experiment = group_experiment
|
||||||
|
|
||||||
def customUpdateDate(self, date):
|
|
||||||
self.date = date
|
|
||||||
|
|
||||||
def customUpdateSpecial(self, special):
|
|
||||||
self.special = special
|
|
||||||
|
|
||||||
def repr(self):
|
def repr(self):
|
||||||
return f"{self.date} {self.group_experiment.repr()}"
|
return f"{self.date} {self.group_experiment.repr()}"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue