mirror of
https://codeberg.org/Mo8it/AdvLabDB.git
synced 2024-11-08 21:21:06 +00:00
Done ExperimentMarkView
This commit is contained in:
parent
3b6f92efd9
commit
64165218ca
3 changed files with 72 additions and 4 deletions
File diff suppressed because one or more lines are too long
|
@ -534,14 +534,76 @@ class ExperimentMarkView(SecureModelView):
|
|||
else:
|
||||
return False
|
||||
|
||||
class CreateForm(Form):
|
||||
part_student = QuerySelectField(
|
||||
"Part Student",
|
||||
query_factory=partStudentsQueryFactory,
|
||||
validators=[DataRequired()],
|
||||
allow_blank=True,
|
||||
blank_text="-",
|
||||
)
|
||||
group_experiment = QuerySelectField(
|
||||
"Group Experiment",
|
||||
query_factory=groupExperimentQueryFactory,
|
||||
validators=[DataRequired()],
|
||||
allow_blank=True,
|
||||
blank_text="-",
|
||||
)
|
||||
|
||||
oral_mark = SelectField("Oral Mark", choices=markChoices, coerce=int)
|
||||
protocol_mark = SelectField("Protocol Mark", choices=markChoices, coerce=int)
|
||||
|
||||
form = CreateForm
|
||||
|
||||
column_filters = [
|
||||
StudentIdFilter(PartStudent.id, "Student / ID"),
|
||||
"part_student.student",
|
||||
"group_experiment.semester_experiment.semester",
|
||||
"group_experiment.semester_experiment.experiment",
|
||||
"assistant",
|
||||
"edited_by_admin",
|
||||
]
|
||||
|
||||
def queryFilter(self=None):
|
||||
return GroupExperiment.semester_experiment_id.in_(
|
||||
[
|
||||
semesterExperiment.id
|
||||
for semesterExperiment in SemesterExperiment.query.filter(
|
||||
SemesterExperiment.semester == userActiveSemester()
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
def checkForm(form):
|
||||
if form.oral_mark.data == -1:
|
||||
form.oral_mark.data = None
|
||||
|
||||
if form.protocol_mark.data == -1:
|
||||
form.protocol_mark.data = None
|
||||
|
||||
return form
|
||||
|
||||
def create_model(self, form):
|
||||
form = ExperimentMarkView.checkForm(form)
|
||||
|
||||
return super().create_model(form)
|
||||
|
||||
def update_model(self, form, model):
|
||||
form = ExperimentMarkView.checkForm(form)
|
||||
|
||||
return super().update_model(form, model)
|
||||
|
||||
def after_model_change(self, form, model, is_created):
|
||||
if model.oral_mark or model.protocol_mark:
|
||||
try:
|
||||
model.edited_by_admin = True
|
||||
|
||||
self.session.commit()
|
||||
except Exception as ex:
|
||||
flash(str(ex), "error")
|
||||
|
||||
self.session.rollback()
|
||||
|
||||
|
||||
admin.add_view(StudentView(Student, db.session))
|
||||
admin.add_view(PartStudentView(PartStudent, db.session))
|
||||
|
|
|
@ -106,7 +106,12 @@ class GroupExperiment(db.Model):
|
|||
f"{student} has already done {semester_experiment.experiment} in {partStudent.part} and had {experimentMark}!"
|
||||
)
|
||||
|
||||
return GroupExperiment(semester_experiment=semester_experiment, group=group)
|
||||
groupExperiment = GroupExperiment(semester_experiment=semester_experiment, group=group)
|
||||
|
||||
for partStudent in group.part_students:
|
||||
db.session.add(ExperimentMark(part_student=partStudent, group_experiment=groupExperiment))
|
||||
|
||||
return groupExperiment
|
||||
|
||||
def repr(self):
|
||||
return f"SemExp {self.semester_experiment.repr()}; Gr {self.group.repr()}"
|
||||
|
@ -125,7 +130,7 @@ class Experiment(db.Model):
|
|||
building = db.Column(db.String(100), nullable=False)
|
||||
responsibility = db.Column(db.String(200), nullable=True)
|
||||
duration_in_days = db.Column(db.Integer, db.CheckConstraint("duration_in_days > -1"), nullable=False)
|
||||
active = db.Column(db.Boolean, nullable=False, default=True)
|
||||
active = db.Column(db.Boolean, default=True, nullable=False)
|
||||
oral_weighting = db.Column(db.Float, nullable=False)
|
||||
protocol_weighting = db.Column(db.Float, nullable=False)
|
||||
final_weighting = db.Column(db.Float, nullable=False)
|
||||
|
@ -187,7 +192,7 @@ class Assistant(db.Model):
|
|||
class Appointment(db.Model):
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
date = db.Column(db.Date, nullable=False) # To be specified with the python package "datetime"
|
||||
special = db.Column(db.Boolean, nullable=False) # In the break or not
|
||||
special = db.Column(db.Boolean, default=False, nullable=False) # In the break or not
|
||||
group_experiment_id = db.Column(db.Integer, db.ForeignKey("group_experiment.id"), nullable=False)
|
||||
assistant_id = db.Column(db.Integer, db.ForeignKey("assistant.id"), nullable=False)
|
||||
|
||||
|
@ -284,6 +289,7 @@ class ExperimentMark(db.Model):
|
|||
protocol_mark = db.Column(
|
||||
db.Integer, db.CheckConstraint("protocol_mark > -1"), db.CheckConstraint("protocol_mark < 16"), nullable=True
|
||||
)
|
||||
edited_by_admin = db.Column(db.Boolean, default=False, nullable=True)
|
||||
part_student_id = db.Column(db.Integer, db.ForeignKey("part_student.id"), nullable=False)
|
||||
group_experiment_id = db.Column(db.Integer, db.ForeignKey("group_experiment.id"), nullable=False)
|
||||
assistant_id = db.Column(
|
||||
|
|
Loading…
Reference in a new issue